0.1.0 • Published 3 years ago

@k6js/contrib-list-plugins v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

List Plugins

atTracking

Adds createdAt and updatedAt fields to a list. These fields are read-only by will be updated automatically when items are created or updated.

Usage

import { atTracking } from '@k6-contrib/list-plugins';

const withAtTracking = atTracking({});

const User = list(withAtTracking({
  ui: {...},
  fields: {...},
  ...
}))

Config

OptionTypeDefaultDescription
createdAtFieldStringcreatedAtName of the createdAt field.
updatedAtFieldStringupdatedAtName of the createdAt field.
formatStringMM/DD/YYYY h:mm AFormat of the generated DateTime field.
accessObjectSee: accessChange default access controls.

access

By default access control on at tracking fields is read only:

{
  read: true,
  create: false,
  update: false
}

Disabling created or updated

You can import either createdAt or updatedAt to apply a single tracking field:

const { createdAt, updatedAt } = require('@keystonejs/list-plugins');

Note: The API is the same.

byTracking

Adds createdBy and updatedBy fields to a list. These fields are read-only by will be updated automatically when items are created or updated.

Usage

import { byTracking } from '@k6-contrib/list-plugins';

const withByTracking = byTracking({});

const User = list(withByTracking({
  ui: {...},
  fields: {...},
  ...
}))

Config

OptionTypeDefaultDescription
createdByFieldStringcreatedByName of the createdBy field.
updatedByFieldStringupdatedByName of the createdBy field.
refStringUserA reference to the list authenticated items (users).
accessObjectSee: accessChange default access controls.

access

By default access control on at tracking fields is read only:

{
  read: true,
  create: false,
  update: false
}

Disabling created or updated

You can import either createdBy or updatedBy to apply a single tracking field:

const { createdBy, updatedBy } = require('@keystonejs/list-plugins');

Note: The API is the same.

singleton

NOT ported

This plugin makes a list singleton by allowing only one item in the list. Useful for list which must contain only one items.

logging

This plugin provides a mechanism for logging all mutations in a Keystone system.

Usage

const { logging } = require('@k6-contrib/list-plugins');

const withLogging = logging();
const withLogging = logging(args => console.log(args));

const User = list(withLogging({
  ui: {...},
  fields: {...},
  ...
}))

Provided hooks

The logging plugin will log the arguments of all mutations with the function args => console.log(JSON.stringify(args)). You can customise its behaviour by providing an alternate logging function.

The plugin provides the following hooks:

  • afterChange
  • afterDelete
  • afterAuth
  • afterUnauth

The logging function for each hook recieves specific arguments related to the mutation.

afterChange (create)

OptionTypeDescription
operationString"create"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
createdItemObjectThe database record of the created item.

afterChange (update)

OptionTypeDescription
operationString"update"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
changedItemObjectThe database record of the updated item. This will only include those fields which have actually been changed.

afterDelete

OptionTypeDescription
operationString"delete"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
deletedItemObjectThe database record of the deleted item.

Deprecated - Not available in keystone 6 yet

afterAuth

OptionTypeDescription
operationString"authenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemObjectThe authenticated item
successBooleanA success indicator returned by authentication strategy
messageStringA success message returned by authentication strategy
tokenStringThe token returned by authentication strategy

afterUnauth

OptionTypeDescription
operationString"unauthenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemIdStringThe ID of the unauthenticated item