@aopslab/domain-kit-docman 0.1.4

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.
Files changed (64) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +79 -0
  4. package/dist/config/config.d.ts +55 -0
  5. package/dist/config/config.js +176 -0
  6. package/dist/domain-services/index.d.ts +7 -0
  7. package/dist/domain-services/index.js +7 -0
  8. package/dist/domain-services/jwt.d.ts +1 -0
  9. package/dist/domain-services/jwt.js +5 -0
  10. package/dist/domain-services/metrics.d.ts +5 -0
  11. package/dist/domain-services/metrics.js +7 -0
  12. package/dist/domain-services/presets.d.ts +3 -0
  13. package/dist/domain-services/presets.js +4 -0
  14. package/dist/domain-services/provider.d.ts +2 -0
  15. package/dist/domain-services/provider.js +564 -0
  16. package/dist/domain-services/resilience.d.ts +6 -0
  17. package/dist/domain-services/resilience.js +19 -0
  18. package/dist/domain-services/types.d.ts +179 -0
  19. package/dist/domain-services/types.js +1 -0
  20. package/dist/domain-services/unified.d.ts +272 -0
  21. package/dist/domain-services/unified.js +210 -0
  22. package/dist/errors/error.map.d.ts +21 -0
  23. package/dist/errors/error.map.js +47 -0
  24. package/dist/errors/friendly.d.ts +31 -0
  25. package/dist/errors/friendly.js +407 -0
  26. package/dist/errors/i18n.d.ts +4 -0
  27. package/dist/errors/i18n.js +10 -0
  28. package/dist/errors/index.d.ts +3 -0
  29. package/dist/errors/index.js +3 -0
  30. package/dist/index.d.ts +9 -0
  31. package/dist/index.js +7 -0
  32. package/dist/operations/catalog.d.ts +11 -0
  33. package/dist/operations/catalog.js +299 -0
  34. package/dist/operations/contract.d.ts +31 -0
  35. package/dist/operations/contract.js +667 -0
  36. package/dist/operations/dcm.d.ts +58 -0
  37. package/dist/operations/dcm.js +168 -0
  38. package/dist/operations/definition.d.ts +6 -0
  39. package/dist/operations/definition.js +140 -0
  40. package/dist/operations/executor.d.ts +10 -0
  41. package/dist/operations/executor.js +269 -0
  42. package/dist/operations/host-projection.d.ts +11 -0
  43. package/dist/operations/host-projection.js +156 -0
  44. package/dist/operations/index.d.ts +10 -0
  45. package/dist/operations/index.js +10 -0
  46. package/dist/operations/io-types.d.ts +125 -0
  47. package/dist/operations/io-types.js +1 -0
  48. package/dist/operations/schemas.d.ts +10 -0
  49. package/dist/operations/schemas.js +872 -0
  50. package/dist/operations/scope-owned-create.d.ts +3 -0
  51. package/dist/operations/scope-owned-create.js +12 -0
  52. package/dist/operations/tool-input.d.ts +11 -0
  53. package/dist/operations/tool-input.js +357 -0
  54. package/dist/operations/types.d.ts +37 -0
  55. package/dist/operations/types.js +1 -0
  56. package/dist/resources/index.d.ts +1 -0
  57. package/dist/resources/index.js +1 -0
  58. package/dist/resources/resources.docman.server.errors.d.ts +14 -0
  59. package/dist/resources/resources.docman.server.errors.js +36 -0
  60. package/dist/shared/index.d.ts +5 -0
  61. package/dist/shared/index.js +1 -0
  62. package/dist/shared/tool-input-guard.d.ts +1 -0
  63. package/dist/shared/tool-input-guard.js +1 -0
  64. package/package.json +69 -0
@@ -0,0 +1,299 @@
1
+ import { cloneDocmanOperationSpec, defineDocmanKitOperation, defineDocmanKitOperations, normalizeDocmanOperationId, } from './definition.js';
2
+ import { createDocmanSchemaRef, getDocmanOperationIoSchemaRefs } from './schemas.js';
3
+ const CRUD_LIST_ARGS = [
4
+ { name: 'filter', optional: true },
5
+ { name: 'options', optional: true },
6
+ ];
7
+ const CRUD_GET_ARGS = [
8
+ { name: 'id', optional: false },
9
+ { name: 'options', optional: true },
10
+ ];
11
+ const CRUD_CREATE_ARGS = [{ name: 'data', optional: false }];
12
+ const CRUD_UPDATE_ARGS = [
13
+ { name: 'id', optional: false },
14
+ { name: 'patch', optional: false },
15
+ ];
16
+ const CRUD_DELETE_ARGS = [{ name: 'id', optional: false }];
17
+ const CRUD_ENTITIES = [
18
+ { entity: 'document', serviceKey: 'documentService', serviceEntityPascal: 'Document' },
19
+ { entity: 'document-group', serviceKey: 'documentGroupService', serviceEntityPascal: 'DocumentGroup' },
20
+ { entity: 'document-version', serviceKey: 'documentVersionService', serviceEntityPascal: 'DocumentVersion' },
21
+ { entity: 'section', serviceKey: 'sectionService', serviceEntityPascal: 'Section' },
22
+ { entity: 'page', serviceKey: 'pageService', serviceEntityPascal: 'Page' },
23
+ { entity: 'page-version', serviceKey: 'pageVersionService', serviceEntityPascal: 'PageVersion' },
24
+ { entity: 'document-section-link', serviceKey: 'documentSectionLinkService', serviceEntityPascal: 'DocumentSectionLink' },
25
+ { entity: 'section-page-link', serviceKey: 'sectionPageLinkService', serviceEntityPascal: 'SectionPageLink' },
26
+ { entity: 'snippet', serviceKey: 'snippetService', serviceEntityPascal: 'Snippet' },
27
+ { entity: 'page-snippet-link', serviceKey: 'pageSnippetLinkService', serviceEntityPascal: 'PageSnippetLink' },
28
+ { entity: 'asset', serviceKey: 'assetService', serviceEntityPascal: 'Asset' },
29
+ { entity: 'asset-version', serviceKey: 'assetVersionService', serviceEntityPascal: 'AssetVersion' },
30
+ { entity: 'embed', serviceKey: 'embedService', serviceEntityPascal: 'Embed' },
31
+ { entity: 'page-embed-link', serviceKey: 'pageEmbedLinkService', serviceEntityPascal: 'PageEmbedLink' },
32
+ ];
33
+ const CUSTOM_OPERATIONS = [
34
+ {
35
+ operationId: 'document.delete.safe',
36
+ serviceKey: 'documentService',
37
+ serviceEntity: 'document',
38
+ methodName: 'removeDocumentSafe',
39
+ args: [
40
+ { name: 'id', optional: false },
41
+ { name: 'confirmName', optional: false },
42
+ ],
43
+ },
44
+ {
45
+ operationId: 'document-version.delete.safe',
46
+ serviceKey: 'documentVersionService',
47
+ serviceEntity: 'document-version',
48
+ methodName: 'removeDocumentVersionSafe',
49
+ args: [{ name: 'id', optional: false }],
50
+ },
51
+ {
52
+ operationId: 'document-version.import-headings',
53
+ serviceKey: 'documentVersionService',
54
+ serviceEntity: 'document-version',
55
+ methodName: 'importHeadings',
56
+ args: [
57
+ { name: 'documentVersionId', optional: false },
58
+ { name: 'scopeId', optional: true },
59
+ { name: 'parsedGraph', optional: false },
60
+ { name: 'options', optional: true },
61
+ { name: 'createdBy', optional: true },
62
+ { name: 'updatedBy', optional: true },
63
+ ],
64
+ },
65
+ {
66
+ operationId: 'document-version.set-current',
67
+ serviceKey: 'documentVersionService',
68
+ serviceEntity: 'document-version',
69
+ methodName: 'setCurrent',
70
+ args: [
71
+ { name: 'documentVersionId', optional: false },
72
+ { name: 'documentId', optional: true },
73
+ { name: 'publish', optional: true },
74
+ { name: 'publishedAt', optional: true },
75
+ { name: 'expectedPreviousVersionId', optional: true },
76
+ ],
77
+ },
78
+ {
79
+ operationId: 'document.compose.index',
80
+ serviceKey: 'documentService',
81
+ serviceEntity: 'document',
82
+ methodName: 'buildDocumentIndex',
83
+ args: [
84
+ { name: 'documentVersionId', optional: false },
85
+ { name: 'options', optional: true },
86
+ ],
87
+ },
88
+ {
89
+ operationId: 'document.index.build',
90
+ serviceKey: 'documentService',
91
+ serviceEntity: 'document',
92
+ methodName: 'buildPersistedDocumentIndex',
93
+ args: [
94
+ { name: 'documentVersionId', optional: false },
95
+ { name: 'locale', optional: true },
96
+ { name: 'fallbackLocale', optional: true },
97
+ ],
98
+ },
99
+ {
100
+ operationId: 'document.index.get',
101
+ serviceKey: 'documentService',
102
+ serviceEntity: 'document',
103
+ methodName: 'getPersistedDocumentIndex',
104
+ args: [
105
+ { name: 'documentVersionId', optional: false },
106
+ { name: 'locale', optional: true },
107
+ { name: 'fallbackLocale', optional: true },
108
+ ],
109
+ },
110
+ {
111
+ operationId: 'document.summary.build',
112
+ serviceKey: 'documentService',
113
+ serviceEntity: 'document',
114
+ methodName: 'buildPersistedDocumentSummary',
115
+ args: [
116
+ { name: 'documentVersionId', optional: false },
117
+ { name: 'locale', optional: true },
118
+ { name: 'fallbackLocale', optional: true },
119
+ ],
120
+ },
121
+ {
122
+ operationId: 'document.summary.get',
123
+ serviceKey: 'documentService',
124
+ serviceEntity: 'document',
125
+ methodName: 'getPersistedDocumentSummary',
126
+ args: [
127
+ { name: 'documentVersionId', optional: false },
128
+ { name: 'locale', optional: true },
129
+ { name: 'fallbackLocale', optional: true },
130
+ ],
131
+ },
132
+ {
133
+ operationId: 'document.search',
134
+ serviceKey: 'documentService',
135
+ serviceEntity: 'document',
136
+ methodName: 'searchPersistedDocumentIndex',
137
+ args: [
138
+ { name: 'documentVersionId', optional: false },
139
+ { name: 'q', optional: false },
140
+ { name: 'limit', optional: true },
141
+ { name: 'retrievalStrategy', optional: true },
142
+ { name: 'locale', optional: true },
143
+ { name: 'fallbackLocale', optional: true },
144
+ ],
145
+ },
146
+ {
147
+ operationId: 'document.scope.search',
148
+ serviceKey: 'documentService',
149
+ serviceEntity: 'document',
150
+ methodName: 'searchScopePersistedDocumentIndex',
151
+ args: [
152
+ { name: 'scopeId', optional: false },
153
+ { name: 'q', optional: false },
154
+ { name: 'limit', optional: true },
155
+ { name: 'retrievalStrategy', optional: true },
156
+ { name: 'locale', optional: true },
157
+ { name: 'fallbackLocale', optional: true },
158
+ ],
159
+ },
160
+ {
161
+ operationId: 'document.answer-pack',
162
+ serviceKey: 'documentService',
163
+ serviceEntity: 'document',
164
+ methodName: 'getDocumentAnswerPack',
165
+ args: [
166
+ { name: 'documentVersionId', optional: false },
167
+ { name: 'q', optional: false },
168
+ { name: 'limit', optional: true },
169
+ { name: 'retrievalStrategy', optional: true },
170
+ { name: 'locale', optional: true },
171
+ { name: 'fallbackLocale', optional: true },
172
+ ],
173
+ },
174
+ {
175
+ operationId: 'document.compose.fetch',
176
+ serviceKey: 'documentService',
177
+ serviceEntity: 'document',
178
+ methodName: 'fetchComposedFragment',
179
+ args: [
180
+ { name: 'documentVersionId', optional: false },
181
+ { name: 'sectionId', optional: true },
182
+ { name: 'pageVersionId', optional: true },
183
+ { name: 'pageNumber', optional: true },
184
+ { name: 'locale', optional: true },
185
+ { name: 'fallbackLocale', optional: true },
186
+ ],
187
+ },
188
+ {
189
+ operationId: 'document.publish.materialize',
190
+ serviceKey: 'documentService',
191
+ serviceEntity: 'document',
192
+ methodName: 'materializePublishedFragment',
193
+ args: [
194
+ { name: 'documentVersionId', optional: false },
195
+ { name: 'target', optional: false },
196
+ { name: 'sectionId', optional: true },
197
+ { name: 'pageVersionId', optional: true },
198
+ { name: 'pageNumber', optional: true },
199
+ { name: 'locale', optional: true },
200
+ { name: 'fallbackLocale', optional: true },
201
+ ],
202
+ },
203
+ {
204
+ operationId: 'document-section-link.usage.list',
205
+ serviceKey: 'documentSectionLinkService',
206
+ serviceEntity: 'document-section-link',
207
+ methodName: 'listDocumentSectionLinkUsageBySectionId',
208
+ args: [{ name: 'sectionId', optional: false }],
209
+ },
210
+ ];
211
+ let cachedOperations = null;
212
+ function toRecord(input) {
213
+ if (!input || typeof input !== 'object' || Array.isArray(input))
214
+ return {};
215
+ return input;
216
+ }
217
+ function buildCrudMethodName(serviceEntityPascal, kind) {
218
+ if (kind === 'list')
219
+ return `list${serviceEntityPascal}s`;
220
+ if (kind === 'get')
221
+ return 'getById';
222
+ if (kind === 'create')
223
+ return 'create';
224
+ if (kind === 'update')
225
+ return `update${serviceEntityPascal}`;
226
+ return `remove${serviceEntityPascal}`;
227
+ }
228
+ function buildCrudOperation(entity, kind, args) {
229
+ const operationId = `${entity.entity}.${kind}`;
230
+ return defineDocmanKitOperation({
231
+ operationId,
232
+ serviceKey: entity.serviceKey,
233
+ serviceEntity: entity.entity,
234
+ methodName: buildCrudMethodName(entity.serviceEntityPascal, kind),
235
+ kind,
236
+ args,
237
+ ...toOperationSchemaRefs(operationId),
238
+ });
239
+ }
240
+ function buildCrudOperations() {
241
+ const operations = [];
242
+ for (const entity of CRUD_ENTITIES) {
243
+ operations.push(buildCrudOperation(entity, 'list', CRUD_LIST_ARGS));
244
+ operations.push(buildCrudOperation(entity, 'get', CRUD_GET_ARGS));
245
+ operations.push(buildCrudOperation(entity, 'create', CRUD_CREATE_ARGS));
246
+ operations.push(buildCrudOperation(entity, 'update', CRUD_UPDATE_ARGS));
247
+ operations.push(buildCrudOperation(entity, 'delete', CRUD_DELETE_ARGS));
248
+ }
249
+ return operations;
250
+ }
251
+ function buildCustomOperations() {
252
+ return defineDocmanKitOperations(CUSTOM_OPERATIONS.map((operation) => ({
253
+ operationId: operation.operationId,
254
+ serviceKey: operation.serviceKey,
255
+ serviceEntity: operation.serviceEntity,
256
+ methodName: operation.methodName,
257
+ kind: 'custom',
258
+ args: operation.args,
259
+ ...toOperationSchemaRefs(operation.operationId),
260
+ })));
261
+ }
262
+ function toOperationSchemaRefs(operationId) {
263
+ const refs = getDocmanOperationIoSchemaRefs(normalizeDocmanOperationId(operationId));
264
+ if (!refs)
265
+ return {};
266
+ return {
267
+ inputSchema: createDocmanSchemaRef(refs.inputRef),
268
+ outputSchema: createDocmanSchemaRef(refs.outputRef),
269
+ };
270
+ }
271
+ function buildOperationsInternal() {
272
+ const operations = [
273
+ ...buildCrudOperations(),
274
+ ...buildCustomOperations(),
275
+ ];
276
+ const unique = new Map();
277
+ for (const operation of operations) {
278
+ unique.set(operation.operationId, operation);
279
+ }
280
+ return [...unique.values()].sort((left, right) => left.operationId.localeCompare(right.operationId));
281
+ }
282
+ export function listDocmanOperationSpecs(options) {
283
+ const opts = toRecord(options);
284
+ const refresh = opts.refresh === true;
285
+ if (!cachedOperations || refresh) {
286
+ cachedOperations = buildOperationsInternal();
287
+ }
288
+ return cachedOperations.map(cloneDocmanOperationSpec);
289
+ }
290
+ export function getDocmanOperationByToolId(toolId, options) {
291
+ const operations = listDocmanOperationSpecs(options);
292
+ return operations.find((operation) => operation.toolId === toolId) ?? null;
293
+ }
294
+ export function getDocmanOperationById(operationId, options) {
295
+ const normalized = normalizeDocmanOperationId(operationId);
296
+ const operations = listDocmanOperationSpecs(options);
297
+ return operations.find((operation) => operation.operationId === normalized) ?? null;
298
+ }
299
+ export { buildDocmanToolIdFromOperation } from './definition.js';
@@ -0,0 +1,31 @@
1
+ import type { DocmanOperationArgument, DocmanOperationEffect, DocmanOperationKind, DocmanOperationPolicy, DocmanOperationSchema } from './types.js';
2
+ export type DocmanOperationSideEffect = DocmanOperationEffect;
3
+ export type DocmanOperationContract = {
4
+ operationId: string;
5
+ toolId: string;
6
+ summary: string;
7
+ kind: DocmanOperationKind;
8
+ sideEffect: DocmanOperationSideEffect;
9
+ serviceKey: string;
10
+ serviceEntity: string;
11
+ methodName: string;
12
+ args: DocmanOperationArgument[];
13
+ tags?: string[];
14
+ inputSchema?: DocmanOperationSchema;
15
+ outputSchema?: DocmanOperationSchema;
16
+ policy?: DocmanOperationPolicy;
17
+ examples?: string[];
18
+ notes?: string[];
19
+ antiPatterns?: string[];
20
+ preconditions?: string[];
21
+ postconditions?: string[];
22
+ };
23
+ export declare function listDocmanOperationContracts(options?: {
24
+ refresh?: boolean;
25
+ }): DocmanOperationContract[];
26
+ export declare function getDocmanOperationContractByToolId(toolId: string, options?: {
27
+ refresh?: boolean;
28
+ }): DocmanOperationContract | null;
29
+ export declare function getDocmanOperationContractById(operationId: string, options?: {
30
+ refresh?: boolean;
31
+ }): DocmanOperationContract | null;