@stonecrop/stonecrop 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "schema helper",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -52,9 +52,9 @@
52
52
  "eslint-plugin-vue": "^9.11.1",
53
53
  "typescript": "^5.6.3",
54
54
  "vite": "^5.4.5",
55
- "@stonecrop/aform": "0.3.5",
55
+ "@stonecrop/aform": "0.3.6",
56
56
  "stonecrop-rig": "0.2.22",
57
- "@stonecrop/atable": "0.3.5"
57
+ "@stonecrop/atable": "0.3.6"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"
@@ -63,8 +63,8 @@
63
63
  "node": ">=20.11.0"
64
64
  },
65
65
  "scripts": {
66
- "prepublish": "heft build && vite build",
67
- "build": "heft build && vite build",
66
+ "prepublish": "heft build && vite build && rushx docs",
67
+ "build": "heft build && vite build && rushx docs",
68
68
  "docs": "api-documenter markdown -i temp -o ../docs/stonecrop",
69
69
  "lint": "eslint . --ext .ts,.vue",
70
70
  "preview": "vite preview"
package/src/composable.ts CHANGED
@@ -4,11 +4,22 @@ import Registry from './registry'
4
4
  import { Stonecrop } from './stonecrop'
5
5
  import { useDataStore } from './stores/data'
6
6
 
7
- type StonecropReturn = {
7
+ /**
8
+ * Stonecrop composable return type
9
+ * @public
10
+ */
11
+ export type StonecropReturn = {
8
12
  stonecrop: Ref<Stonecrop>
9
13
  isReady: Ref<boolean>
10
14
  }
11
15
 
16
+ /**
17
+ * Stonecrop composable
18
+ * @param registry - An existing Stonecrop Registry instance
19
+ * @returns The Stonecrop instance and a boolean indicating if Stonecrop is setup and ready
20
+ * @throws Error if the Stonecrop plugin is not enabled before using the composable
21
+ * @public
22
+ */
12
23
  export function useStonecrop(registry?: Registry): StonecropReturn {
13
24
  if (!registry) {
14
25
  registry = inject<Registry>('$registry')
package/src/doctype.ts CHANGED
@@ -2,14 +2,47 @@ import { Component } from 'vue'
2
2
 
3
3
  import type { ImmutableDoctype } from './types'
4
4
 
5
+ /**
6
+ * Doctype Meta class
7
+ * @public
8
+ */
5
9
  export default class DoctypeMeta {
10
+ /**
11
+ * The doctype name
12
+ * @public
13
+ * @readonly
14
+ */
6
15
  readonly doctype: string
16
+
17
+ /**
18
+ * The doctype schema
19
+ * @public
20
+ * @readonly
21
+ */
7
22
  readonly schema: ImmutableDoctype['schema']
23
+
24
+ /**
25
+ * The doctype workflow
26
+ * @public
27
+ * @readonly
28
+ */
8
29
  readonly workflow: ImmutableDoctype['workflow']
30
+
31
+ /**
32
+ * The doctype actions
33
+ * @public
34
+ * @readonly
35
+ */
9
36
  readonly actions: ImmutableDoctype['actions']
37
+
38
+ /**
39
+ * The doctype component
40
+ * @public
41
+ * @readonly
42
+ */
43
+ readonly component?: Component
10
44
  // TODO: allow different components for different views; probably
11
45
  // should be defined in the schema instead?
12
- readonly component?: Component
13
46
 
14
47
  constructor(
15
48
  doctype: string,
@@ -25,15 +58,15 @@ export default class DoctypeMeta {
25
58
  this.component = component
26
59
  }
27
60
 
61
+ /**
62
+ * Converts the registered doctype to a slug (kebab-case)
63
+ * @returns The slugified doctype string
64
+ * @public
65
+ */
28
66
  get slug() {
29
- // kebab case
30
67
  return this.doctype
31
68
  .replace(/([a-z])([A-Z])/g, '$1-$2')
32
69
  .replace(/[\s_]+/g, '-')
33
70
  .toLowerCase()
34
71
  }
35
-
36
- get __typename() {
37
- return this.doctype
38
- }
39
72
  }
package/src/index.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { useStonecrop } from './composable'
1
+ export type { BaseSchema, FieldsetSchema, FormSchema, SchemaTypes, TableSchema } from '@stonecrop/aform'
2
+ export type { CellContext, TableColumn, TableConfig, TableRow } from '@stonecrop/atable'
3
+
4
+ import { type StonecropReturn, useStonecrop } from './composable'
2
5
  import DoctypeMeta from './doctype'
3
6
  import Registry from './registry'
4
7
  import Stonecrop from './plugins'
5
8
  export type { ImmutableDoctype, MutableDoctype, Schema, InstallOptions } from './types'
6
9
 
7
- export { DoctypeMeta, Registry, Stonecrop, useStonecrop }
10
+ export { DoctypeMeta, Registry, Stonecrop, StonecropReturn, useStonecrop }
@@ -5,6 +5,34 @@ import router from '../router'
5
5
  import { pinia } from '../stores'
6
6
  import type { InstallOptions } from '../types'
7
7
 
8
+ /**
9
+ * Stonecrop Vue plugin
10
+ * @param app - The Vue app instance
11
+ * @param options - The plugin options
12
+ * @example
13
+ * ```ts
14
+ *
15
+ * import { createApp } from 'vue'
16
+ * import Stonecrop from 'stonecrop'
17
+ *
18
+ * import App from './App.vue'
19
+ *
20
+ * const app = createApp(App)
21
+ * app.use(Stonecrop, {
22
+ * router,
23
+ * components: {
24
+ * // register custom components
25
+ * },
26
+ * getMeta: async (doctype: string) => {
27
+ * // fetch doctype meta from API
28
+ * },
29
+ * })
30
+ *
31
+ * app.mount('#app')
32
+ * ```
33
+ *
34
+ * @public
35
+ */
8
36
  const plugin: Plugin = {
9
37
  install: (app: App, options?: InstallOptions) => {
10
38
  const appRouter = options?.router || router
package/src/registry.ts CHANGED
@@ -2,11 +2,39 @@ import { Router } from 'vue-router'
2
2
 
3
3
  import DoctypeMeta from './doctype'
4
4
 
5
+ /**
6
+ * Stonecrop Registry class
7
+ * @public
8
+ */
5
9
  export default class Registry {
10
+ /**
11
+ * The root Registry instance
12
+ */
6
13
  static _root: Registry
14
+
15
+ /**
16
+ * The name of the Registry instance
17
+ *
18
+ * @defaultValue 'Registry'
19
+ */
7
20
  name: string
21
+
22
+ /**
23
+ * The Vue router instance
24
+ * @see {@link https://router.vuejs.org/}
25
+ */
8
26
  router: Router
27
+
28
+ /**
29
+ * The registry property contains a collection of doctypes
30
+ * @see {@link DoctypeMeta}
31
+ */
9
32
  registry: Record<string, DoctypeMeta>
33
+
34
+ /**
35
+ * The getMeta function fetches doctype metadata from an API
36
+ * @see {@link DoctypeMeta}
37
+ */
10
38
  getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>
11
39
 
12
40
  constructor(router: Router, getMeta?: (doctype: string) => DoctypeMeta | Promise<DoctypeMeta>) {
@@ -20,6 +48,12 @@ export default class Registry {
20
48
  this.getMeta = getMeta
21
49
  }
22
50
 
51
+ /**
52
+ * Get doctype metadata
53
+ * @param doctype - The doctype to fetch metadata for
54
+ * @returns The doctype metadata
55
+ * @see {@link DoctypeMeta}
56
+ */
23
57
  addDoctype(doctype: DoctypeMeta) {
24
58
  if (!(doctype.doctype in Object.keys(this.registry))) {
25
59
  this.registry[doctype.slug] = doctype
package/src/stonecrop.ts CHANGED
@@ -4,25 +4,28 @@ import Registry from './registry'
4
4
  import { useDataStore } from './stores/data'
5
5
  import type { ImmutableDoctype, Schema } from './types'
6
6
 
7
+ /**
8
+ * Stonecrop class
9
+ * @public
10
+ */
7
11
  export class Stonecrop {
8
12
  /**
9
- * @property {Stonecrop} _root
10
- * @description The root Stonecrop instance
13
+ * The root Stonecrop instance
11
14
  */
12
15
  static _root: Stonecrop
13
16
 
14
17
  /**
15
- * @property {string} name
16
- * @description The name of the Stonecrop instance
17
- * @example
18
- * 'Stonecrop'
18
+ * The name of the Stonecrop instance
19
+ * @readonly
20
+ *
21
+ * @defaultValue 'Stonecrop'
19
22
  */
20
23
  readonly name = 'Stonecrop'
21
24
 
22
25
  /**
23
- * @property {Registry} registry
24
- * @description The registry is an immutable collection of doctypes
26
+ * The registry is an immutable collection of doctypes
25
27
  * @example
28
+ * ```ts
26
29
  * {
27
30
  * 'task': {
28
31
  * doctype: 'Task',
@@ -34,15 +37,16 @@ export class Stonecrop {
34
37
  * },
35
38
  * ...
36
39
  * }
40
+ * ```
37
41
  * @see {@link Registry}
38
42
  * @see {@link DoctypeMeta}
39
43
  */
40
44
  readonly registry: Registry
41
45
 
42
46
  /**
43
- * @property {Schema} schema - The Stonecrop schema
44
- * @description The schema is a subset of the registry
47
+ * schema - The Stonecrop schema; the schema is a subset of the registry
45
48
  * @example
49
+ * ```ts
46
50
  * {
47
51
  * doctype: 'Task',
48
52
  * schema: {
@@ -51,6 +55,7 @@ export class Stonecrop {
51
55
  * ...
52
56
  * }
53
57
  * }
58
+ * ```
54
59
  * @see {@link Registry}
55
60
  * @see {@link DoctypeMeta}
56
61
  * @see {@link DoctypeMeta.schema}
@@ -58,36 +63,33 @@ export class Stonecrop {
58
63
  schema: Schema
59
64
 
60
65
  /**
61
- * @property {ImmutableDoctype['workflow']} workflow
62
- * @description The workflow is a subset of the registry
66
+ * The workflow is a subset of the registry
63
67
  */
64
68
  workflow: ImmutableDoctype['workflow']
65
69
 
66
70
  /**
67
- * @property {ImmutableDoctype['actions']} actions
68
- * @description The actions are a subset of the registry
71
+ * The actions are a subset of the registry
69
72
  */
70
73
  actions: ImmutableDoctype['actions']
71
74
 
72
75
  /**
73
- * @property {ReturnType<typeof useDataStore>} store
74
- * @description The Pinia store that manages the mutable records
76
+ * The Pinia store that manages the mutable records
75
77
  */
76
78
  store: ReturnType<typeof useDataStore>
77
79
 
78
80
  /**
79
- * @constructor
80
- * @param {Registry} registry - The immutable registry
81
- * @param {ReturnType<typeof useDataStore>} store - The mutable Pinia store
82
- * @param {Schema} [schema] - (optional) The Stonecrop schema
83
- * @param {ImmutableDoctype['workflow']} [workflow] - (optional) The Stonecrop workflow
84
- * @param {ImmutableDoctype['actions']} [actions] - (optional) The Stonecrop actions
85
- * @returns {Stonecrop} The Stonecrop instance
86
- * @description The Stonecrop constructor initializes a new Stonecrop instance with the given registry, store, schema, workflow, and actions. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
81
+ * @param registry - The immutable registry
82
+ * @param store - The mutable Pinia store
83
+ * @param schema - The Stonecrop schema
84
+ * @param workflow - The Stonecrop workflow
85
+ * @param actions - The Stonecrop actions
86
+ * @returns The Stonecrop instance with the given registry, store, schema, workflow, and actions. If a Stonecrop instance has already been created, it returns the existing instance instead of creating a new one.
87
87
  * @example
88
+ * ```ts
88
89
  * const registry = new Registry()
89
90
  * const store = useDataStore()
90
- * const stonecrop = new Stonecrop(registry, store, schema, workflow, actions)
91
+ * const stonecrop = new Stonecrop(registry, store)
92
+ * ```
91
93
  */
92
94
  constructor(
93
95
  registry: Registry,
@@ -108,13 +110,13 @@ export class Stonecrop {
108
110
  }
109
111
 
110
112
  /**
111
- * @method setup
112
- * @param {DoctypeMeta} doctype - The doctype to setup
113
- * @returns {void}
114
- * @description Sets up the Stonecrop instance with the given doctype
113
+ * Sets up the Stonecrop instance with the given doctype
114
+ * @param doctype - The doctype to setup
115
115
  * @example
116
+ * ```ts
116
117
  * const doctype = await registry.getMeta('Task')
117
118
  * stonecrop.setup(doctype)
119
+ * ```
118
120
  */
119
121
  setup(doctype: DoctypeMeta): void {
120
122
  void this.getMeta(doctype)
@@ -123,28 +125,29 @@ export class Stonecrop {
123
125
  }
124
126
 
125
127
  /**
126
- * @method getMeta
127
- * @param {DoctypeMeta} doctype - The doctype to get meta for
128
- * @returns {DoctypeMeta}
129
- * @see {@link DoctypeMeta}
128
+ * Gets the meta for the given doctype
129
+ * @param doctype - The doctype to get meta for
130
+ * @returns The meta for the given doctype
130
131
  * @throws NotImplementedError
131
- * @description Gets the meta for the given doctype
132
132
  * @example
133
+ * ```ts
133
134
  * const doctype = await registry.getMeta('Task')
134
135
  * const meta = stonecrop.getMeta(doctype)
136
+ * ```
137
+ * @see {@link DoctypeMeta}
135
138
  */
136
139
  getMeta(doctype: DoctypeMeta): DoctypeMeta | Promise<DoctypeMeta> | never {
137
140
  return this.registry.getMeta ? this.registry.getMeta(doctype.doctype) : new NotImplementedError(doctype.doctype)
138
141
  }
139
142
 
140
143
  /**
141
- * @method getWorkflow
142
- * @param {DoctypeMeta} doctype - The doctype to get workflow for
143
- * @returns {void}
144
- * @description Gets the workflow for the given doctype
144
+ * Gets the workflow for the given doctype
145
+ * @param doctype - The doctype to get workflow for
145
146
  * @example
147
+ * ```ts
146
148
  * const doctype = await registry.getMeta('Task')
147
149
  * stonecrop.getWorkflow(doctype)
150
+ * ```
148
151
  */
149
152
  getWorkflow(doctype: DoctypeMeta): void {
150
153
  const doctypeRegistry = this.registry.registry[doctype.slug]
@@ -152,13 +155,13 @@ export class Stonecrop {
152
155
  }
153
156
 
154
157
  /**
155
- * @method getActions
156
- * @param {DoctypeMeta} doctype - The doctype to get actions for
157
- * @returns {void}
158
- * @description Gets the actions for the given doctype
158
+ * Gets the actions for the given doctype
159
+ * @param doctype - The doctype to get actions for
159
160
  * @example
161
+ * ```ts
160
162
  * const doctype = await registry.getMeta('Task')
161
163
  * stonecrop.getActions(doctype)
164
+ * ```
162
165
  */
163
166
  getActions(doctype: DoctypeMeta): void {
164
167
  const doctypeRegistry = this.registry.registry[doctype.slug]
@@ -166,18 +169,20 @@ export class Stonecrop {
166
169
  }
167
170
 
168
171
  /**
169
- * @method getRecords
170
- * @param {DoctypeMeta} doctype - The doctype to get records for
171
- * @param {RequestInit} [filters] - The filters to apply to the records
172
- * @returns {Promise<void>}
173
- * @description Gets the records for the given doctype
172
+ * Gets the records for the given doctype
173
+ * @param doctype - The doctype to get records for
174
+ * @param filters - The filters to apply to the records
174
175
  * @example
176
+ * ```ts
175
177
  * const doctype = await registry.getMeta('Task')
176
178
  * await stonecrop.getRecords(doctype)
179
+ * ```
177
180
  * @example
181
+ * ```ts
178
182
  * const doctype = await registry.getMeta('Task')
179
183
  * const filters = JSON.stringify({ status: 'Open' })
180
184
  * await stonecrop.getRecords(doctype, { body: filters })
185
+ * ```
181
186
  */
182
187
  async getRecords(doctype: DoctypeMeta, filters?: RequestInit): Promise<void> {
183
188
  this.store.$patch({ records: [] })
@@ -187,14 +192,14 @@ export class Stonecrop {
187
192
  }
188
193
 
189
194
  /**
190
- * @method getRecord
191
- * @param {DoctypeMeta} doctype - The doctype to get record for
192
- * @param {string} id - The id of the record to get
193
- * @returns {Promise<void>}
194
- * @description Gets the record for the given doctype and id
195
+ * Gets the record for the given doctype and id
196
+ * @param doctype - The doctype to get record for
197
+ * @param id - The id of the record to get
195
198
  * @example
199
+ * ```ts
196
200
  * const doctype = await registry.getMeta('Task')
197
201
  * await stonecrop.getRecord(doctype, 'TASK-00001')
202
+ * ```
198
203
  */
199
204
  async getRecord(doctype: DoctypeMeta, id: string): Promise<void> {
200
205
  this.store.$patch({ record: {} })
@@ -204,24 +209,30 @@ export class Stonecrop {
204
209
  }
205
210
 
206
211
  /**
207
- * @method runAction
208
- * @param {DoctypeMeta} doctype - The doctype to run action for
209
- * @param {string} action - The action to run
210
- * @param {string[]} [id] - The id(s) of the record(s) to run action on
211
- * @returns {void}
212
- * @description Runs the action for the given doctype and id
212
+ * Runs the action for the given doctype and id
213
+ * @param doctype - The doctype to run action for
214
+ * @param action - The action to run
215
+ * @param id - The id(s) of the record(s) to run action on
213
216
  * @example
217
+ * ```ts
214
218
  * const doctype = await registry.getMeta('Task')
215
219
  * stonecrop.runAction(doctype, 'CREATE')
220
+ * ```
216
221
  * @example
222
+ * ```ts
217
223
  * const doctype = await registry.getMeta('Task')
218
224
  * stonecrop.runAction(doctype, 'UPDATE', ['TASK-00001'])
225
+ * ```
219
226
  * @example
227
+ * ```ts
220
228
  * const doctype = await registry.getMeta('Task')
221
229
  * stonecrop.runAction(doctype, 'DELETE', ['TASK-00001'])
230
+ * ```
222
231
  * @example
232
+ * ```ts
223
233
  * const doctype = await registry.getMeta('Task')
224
234
  * stonecrop.runAction(doctype, 'TRANSITION', ['TASK-00001', 'TASK-00002'])
235
+ * ```
225
236
  */
226
237
  runAction(doctype: DoctypeMeta, action: string, id?: string[]): void {
227
238
  const doctypeRegistry = this.registry.registry[doctype.slug]
@@ -6,6 +6,10 @@ import { MachineConfig, StateMachine } from 'xstate'
6
6
 
7
7
  import DoctypeMeta from '../doctype'
8
8
 
9
+ /**
10
+ * Immutable Doctype type for Stonecrop instances
11
+ * @public
12
+ */
9
13
  export type ImmutableDoctype = {
10
14
  // TODO: allow schema to be a function
11
15
  readonly schema?: List<SchemaTypes>
@@ -13,6 +17,10 @@ export type ImmutableDoctype = {
13
17
  readonly actions?: Map<string, string[]>
14
18
  }
15
19
 
20
+ /**
21
+ * Mutable Doctype type for Stonecrop instances
22
+ * @public
23
+ */
16
24
  export type MutableDoctype = {
17
25
  // TODO: allow schema to be a function
18
26
  schema?: SchemaTypes[]
@@ -20,11 +28,19 @@ export type MutableDoctype = {
20
28
  actions?: Record<string, string[]>
21
29
  }
22
30
 
31
+ /**
32
+ * Schema type for Stonecrop instances
33
+ * @public
34
+ */
23
35
  export type Schema = {
24
36
  doctype: string
25
37
  schema: List<SchemaTypes>
26
38
  }
27
39
 
40
+ /**
41
+ * Install options for Stonecrop Vue plugin
42
+ * @public
43
+ */
28
44
  export type InstallOptions = {
29
45
  router?: Router
30
46
  components?: Record<string, Component>