@3sixty/data-processing-service 0.0.0-stage → 0.20.0-next.1

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 (46) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/dataProcessingRoutes.js +384 -0
  4. package/dist/es/dataProcessingRoutes.js.map +1 -0
  5. package/dist/es/dataProcessingService.js +175 -0
  6. package/dist/es/dataProcessingService.js.map +1 -0
  7. package/dist/es/entities/extractionRule.js +43 -0
  8. package/dist/es/entities/extractionRule.js.map +1 -0
  9. package/dist/es/entities/extractionRuleGroup.js +37 -0
  10. package/dist/es/entities/extractionRuleGroup.js.map +1 -0
  11. package/dist/es/index.js +10 -0
  12. package/dist/es/index.js.map +1 -0
  13. package/dist/es/models/IDataProcessingServiceConstructorOptions.js +4 -0
  14. package/dist/es/models/IDataProcessingServiceConstructorOptions.js.map +1 -0
  15. package/dist/es/restEntryPoints.js +13 -0
  16. package/dist/es/restEntryPoints.js.map +1 -0
  17. package/dist/es/schema.js +13 -0
  18. package/dist/es/schema.js.map +1 -0
  19. package/dist/types/dataProcessingRoutes.d.ts +61 -0
  20. package/dist/types/dataProcessingService.d.ts +73 -0
  21. package/dist/types/entities/extractionRule.d.ts +22 -0
  22. package/dist/types/entities/extractionRuleGroup.d.ts +18 -0
  23. package/dist/types/index.d.ts +7 -0
  24. package/dist/types/models/IDataProcessingServiceConstructorOptions.d.ts +14 -0
  25. package/dist/types/restEntryPoints.d.ts +5 -0
  26. package/dist/types/schema.d.ts +4 -0
  27. package/docs/changelog.md +19 -0
  28. package/docs/examples.md +112 -0
  29. package/docs/open-api/spec.json +894 -0
  30. package/docs/reference/classes/DataProcessingService.md +244 -0
  31. package/docs/reference/classes/ExtractionRule.md +45 -0
  32. package/docs/reference/classes/ExtractionRuleGroup.md +37 -0
  33. package/docs/reference/functions/dataProcessingConvert.md +31 -0
  34. package/docs/reference/functions/dataProcessingExtract.md +31 -0
  35. package/docs/reference/functions/dataProcessingGetRuleGroup.md +31 -0
  36. package/docs/reference/functions/dataProcessingRemoveRuleGroup.md +31 -0
  37. package/docs/reference/functions/dataProcessingSetRuleGroup.md +31 -0
  38. package/docs/reference/functions/generateRestRoutesDataProcessing.md +25 -0
  39. package/docs/reference/functions/initSchema.md +9 -0
  40. package/docs/reference/functions/ruleGroupList.md +31 -0
  41. package/docs/reference/index.md +27 -0
  42. package/docs/reference/interfaces/IDataProcessingServiceConstructorOptions.md +25 -0
  43. package/docs/reference/variables/restEntryPoints.md +5 -0
  44. package/docs/reference/variables/tagsDataProcessing.md +5 -0
  45. package/locales/en.json +10 -0
  46. package/package.json +59 -5
@@ -0,0 +1,175 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { GeneralError, Guards, Is, NotFoundError, ObjectHelper } from "@3sixty/core";
4
+ import { DataConverterConnectorFactory, DataExtractorConnectorFactory } from "@3sixty/data-processing-models";
5
+ import { SortDirection } from "@3sixty/entity";
6
+ import { EntityStorageConnectorFactory } from "@3sixty/entity-storage-models";
7
+ import { MimeTypeHelper } from "@3sixty/web";
8
+ /**
9
+ * Class for processing data from a source.
10
+ */
11
+ export class DataProcessingService {
12
+ /**
13
+ * Runtime name for the class.
14
+ */
15
+ static CLASS_NAME = "DataProcessingService";
16
+ /**
17
+ * The entity storage for the extraction rule groups.
18
+ * @internal
19
+ */
20
+ _extractionRuleGroupStorage;
21
+ /**
22
+ * The extractor connection to use.
23
+ * @internal
24
+ */
25
+ _extractorConnector;
26
+ /**
27
+ * Create a new instance of DataExtractionService.
28
+ * @param options The options for the connector.
29
+ * @throws GeneralError If no extractor connector is registered.
30
+ */
31
+ constructor(options) {
32
+ this._extractionRuleGroupStorage = EntityStorageConnectorFactory.get(options?.extractionRuleGroupStorageConnectorType ?? "extraction-rule-group");
33
+ if (Is.stringValue(options?.defaultExtractorType)) {
34
+ this._extractorConnector = DataExtractorConnectorFactory.get(options.defaultExtractorType);
35
+ }
36
+ else {
37
+ const names = DataExtractorConnectorFactory.names();
38
+ if (names.length > 0) {
39
+ this._extractorConnector = DataExtractorConnectorFactory.get(names[0]);
40
+ }
41
+ else {
42
+ throw new GeneralError(DataProcessingService.CLASS_NAME, "noExtractorFound");
43
+ }
44
+ }
45
+ }
46
+ /**
47
+ * Returns the class name of the component.
48
+ * @returns The class name of the component.
49
+ */
50
+ className() {
51
+ return DataProcessingService.CLASS_NAME;
52
+ }
53
+ /**
54
+ * Set an extraction rule group.
55
+ * @param ruleGroup The rule group to store.
56
+ * @returns A promise that resolves when the rule group has been stored.
57
+ */
58
+ async ruleGroupSet(ruleGroup) {
59
+ Guards.object(DataProcessingService.CLASS_NAME, "ruleGroup", ruleGroup);
60
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "ruleGroup.id", ruleGroup.id);
61
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "ruleGroup.label", ruleGroup.label);
62
+ Guards.array(DataProcessingService.CLASS_NAME, "ruleGroup.rules", ruleGroup.rules);
63
+ for (const rule of ruleGroup.rules) {
64
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "rule.source", rule.source);
65
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "rule.target", rule.source);
66
+ }
67
+ const extractionRuleGroup = {
68
+ id: ruleGroup.id,
69
+ label: ruleGroup.label,
70
+ rules: ruleGroup.rules.map(rule => ({
71
+ source: rule.source,
72
+ target: rule.target,
73
+ retainPathDepth: rule.retainPathDepth,
74
+ coerce: rule.coerce
75
+ }))
76
+ };
77
+ await this._extractionRuleGroupStorage.set(extractionRuleGroup);
78
+ }
79
+ /**
80
+ * Get a rule group for extraction.
81
+ * @param ruleGroupId The id of the rule group to get.
82
+ * @returns The rule group.
83
+ */
84
+ async ruleGroupGet(ruleGroupId) {
85
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "ruleGroupId", ruleGroupId);
86
+ const extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);
87
+ if (Is.empty(extractRuleGroup)) {
88
+ throw new NotFoundError(DataProcessingService.CLASS_NAME, "ruleGroupNotFound", ruleGroupId);
89
+ }
90
+ return {
91
+ id: extractRuleGroup.id,
92
+ label: extractRuleGroup.label,
93
+ rules: extractRuleGroup.rules.map(rule => ({
94
+ source: rule.source,
95
+ target: rule.target,
96
+ retainPathDepth: rule.retainPathDepth,
97
+ coerce: rule.coerce
98
+ }))
99
+ };
100
+ }
101
+ /**
102
+ * Remove a rule group.
103
+ * @param ruleGroupId The id of the rule group to remove.
104
+ * @returns A promise that resolves when the rule group has been removed.
105
+ */
106
+ async ruleGroupRemove(ruleGroupId) {
107
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "ruleGroupId", ruleGroupId);
108
+ const extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);
109
+ if (Is.empty(extractRuleGroup)) {
110
+ throw new NotFoundError(DataProcessingService.CLASS_NAME, "ruleGroupNotFound", ruleGroupId);
111
+ }
112
+ await this._extractionRuleGroupStorage.remove(ruleGroupId);
113
+ }
114
+ /**
115
+ * Extracts data from the provided input.
116
+ * @param ruleGroupId The id of the rule group to use to extract data.
117
+ * @param data The data to extract from.
118
+ * @param overrideExtractorType An optional override for the extractor type.
119
+ * @param overrideMimeType An optional override for the mime type for conversion, will auto detect if not provided.
120
+ * @returns The extracted data.
121
+ */
122
+ async extract(ruleGroupId, data, overrideExtractorType, overrideMimeType) {
123
+ Guards.stringValue(DataProcessingService.CLASS_NAME, "ruleGroupId", ruleGroupId);
124
+ Guards.uint8Array(DataProcessingService.CLASS_NAME, "data", data);
125
+ const extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);
126
+ if (Is.empty(extractRuleGroup)) {
127
+ throw new NotFoundError(DataProcessingService.CLASS_NAME, "ruleGroupNotFound", ruleGroupId);
128
+ }
129
+ const converted = await this.convert(data, overrideMimeType);
130
+ const extractor = Is.empty(overrideExtractorType)
131
+ ? this._extractorConnector
132
+ : DataExtractorConnectorFactory.get(overrideExtractorType);
133
+ const extracted = await extractor.extract(converted, extractRuleGroup.rules);
134
+ return ObjectHelper.toExtended(extracted);
135
+ }
136
+ /**
137
+ * Converts data from the provided input to a structured JSON document.
138
+ * @param data The data to convert.
139
+ * @param overrideMimeType An optional override for the mime type, will auto detect if empty.
140
+ * @returns The converted data.
141
+ */
142
+ async convert(data, overrideMimeType) {
143
+ Guards.uint8Array(DataProcessingService.CLASS_NAME, "data", data);
144
+ const mimeType = overrideMimeType ?? (await MimeTypeHelper.detect(data));
145
+ if (Is.empty(mimeType)) {
146
+ throw new GeneralError(DataProcessingService.CLASS_NAME, "mimeTypeNotFound");
147
+ }
148
+ const converters = DataConverterConnectorFactory.instancesList();
149
+ const converter = converters.find(c => c.mimeTypes().includes(mimeType));
150
+ if (Is.empty(converter)) {
151
+ throw new NotFoundError(DataProcessingService.CLASS_NAME, "converterNotFound", mimeType);
152
+ }
153
+ return converter.convert(data);
154
+ }
155
+ /**
156
+ * Query the rule group entries.
157
+ * @param cursor The cursor to request the next chunk of entities.
158
+ * @param limit Limit the number of entities to return.
159
+ * @returns All the entities for the storage matching the conditions,
160
+ * and a cursor which can be used to request more entities.
161
+ */
162
+ async query(cursor, limit) {
163
+ const result = await this._extractionRuleGroupStorage.query(undefined, [
164
+ {
165
+ property: "id",
166
+ sortDirection: SortDirection.Descending
167
+ }
168
+ ], undefined, cursor, limit);
169
+ return {
170
+ entities: result.entities,
171
+ cursor: result.cursor
172
+ };
173
+ }
174
+ }
175
+ //# sourceMappingURL=dataProcessingService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataProcessingService.js","sources":["../../src/dataProcessingService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EACN,6BAA6B,EAC7B,6BAA6B,EAK7B,MAAM,gCA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AAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzE,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,aAAa,CAAC,qBAAqB,CAAC,UAAU,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QAC1F,CAAC;QAED,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,CACjB,MAAe,EACf,KAAc;QAWd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAC1D,SAAS,EACT;YACC;gBACC,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,aAAa,CAAC,UAAU;aACvC;SACD,EACD,SAAS,EACT,MAAM,EACN,KAAK,CACL,CAAC;QAEF,OAAO;YACN,QAAQ,EAAE,MAAM,CAAC,QAAwB;YACzC,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is, NotFoundError, ObjectHelper } from \"@3sixty/core\";\nimport {\n\tDataConverterConnectorFactory,\n\tDataExtractorConnectorFactory,\n\ttype IDataExtractorConnector,\n\ttype IDataProcessingComponent,\n\ttype IRule,\n\ttype IRuleGroup\n} from \"@3sixty/data-processing-models\";\nimport { SortDirection } from \"@3sixty/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@3sixty/entity-storage-models\";\n\nimport { MimeTypeHelper } from \"@3sixty/web\";\nimport type { ExtractionRuleGroup } from \"./entities/extractionRuleGroup.js\";\nimport type { IDataProcessingServiceConstructorOptions } from \"./models/IDataProcessingServiceConstructorOptions.js\";\n\n/**\n * Class for processing data from a source.\n */\nexport class DataProcessingService implements IDataProcessingComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"DataProcessingService\";\n\n\t/**\n\t * The entity storage for the extraction rule groups.\n\t * @internal\n\t */\n\tprivate readonly _extractionRuleGroupStorage: IEntityStorageConnector<ExtractionRuleGroup>;\n\n\t/**\n\t * The extractor connection to use.\n\t * @internal\n\t */\n\tprivate readonly _extractorConnector: IDataExtractorConnector;\n\n\t/**\n\t * Create a new instance of DataExtractionService.\n\t * @param options The options for the connector.\n\t * @throws GeneralError If no extractor connector is registered.\n\t */\n\tconstructor(options?: IDataProcessingServiceConstructorOptions) {\n\t\tthis._extractionRuleGroupStorage = EntityStorageConnectorFactory.get(\n\t\t\toptions?.extractionRuleGroupStorageConnectorType ?? \"extraction-rule-group\"\n\t\t);\n\n\t\tif (Is.stringValue(options?.defaultExtractorType)) {\n\t\t\tthis._extractorConnector = DataExtractorConnectorFactory.get(options.defaultExtractorType);\n\t\t} else {\n\t\t\tconst names = DataExtractorConnectorFactory.names();\n\t\t\tif (names.length > 0) {\n\t\t\t\tthis._extractorConnector = DataExtractorConnectorFactory.get(names[0]);\n\t\t\t} else {\n\t\t\t\tthrow new GeneralError(DataProcessingService.CLASS_NAME, \"noExtractorFound\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DataProcessingService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Set an extraction rule group.\n\t * @param ruleGroup The rule group to store.\n\t * @returns A promise that resolves when the rule group has been stored.\n\t */\n\tpublic async ruleGroupSet(ruleGroup: IRuleGroup): Promise<void> {\n\t\tGuards.object<IRuleGroup>(DataProcessingService.CLASS_NAME, \"ruleGroup\", ruleGroup);\n\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"ruleGroup.id\", ruleGroup.id);\n\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"ruleGroup.label\", ruleGroup.label);\n\t\tGuards.array<IRule>(DataProcessingService.CLASS_NAME, \"ruleGroup.rules\", ruleGroup.rules);\n\n\t\tfor (const rule of ruleGroup.rules) {\n\t\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"rule.source\", rule.source);\n\t\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"rule.target\", rule.source);\n\t\t}\n\n\t\tconst extractionRuleGroup: ExtractionRuleGroup = {\n\t\t\tid: ruleGroup.id,\n\t\t\tlabel: ruleGroup.label,\n\t\t\trules: ruleGroup.rules.map(rule => ({\n\t\t\t\tsource: rule.source,\n\t\t\t\ttarget: rule.target,\n\t\t\t\tretainPathDepth: rule.retainPathDepth,\n\t\t\t\tcoerce: rule.coerce\n\t\t\t}))\n\t\t};\n\n\t\tawait this._extractionRuleGroupStorage.set(extractionRuleGroup);\n\t}\n\n\t/**\n\t * Get a rule group for extraction.\n\t * @param ruleGroupId The id of the rule group to get.\n\t * @returns The rule group.\n\t */\n\tpublic async ruleGroupGet(ruleGroupId: string): Promise<IRuleGroup> {\n\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"ruleGroupId\", ruleGroupId);\n\n\t\tconst extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);\n\n\t\tif (Is.empty(extractRuleGroup)) {\n\t\t\tthrow new NotFoundError(DataProcessingService.CLASS_NAME, \"ruleGroupNotFound\", ruleGroupId);\n\t\t}\n\n\t\treturn {\n\t\t\tid: extractRuleGroup.id,\n\t\t\tlabel: extractRuleGroup.label,\n\t\t\trules: extractRuleGroup.rules.map(rule => ({\n\t\t\t\tsource: rule.source,\n\t\t\t\ttarget: rule.target,\n\t\t\t\tretainPathDepth: rule.retainPathDepth,\n\t\t\t\tcoerce: rule.coerce\n\t\t\t}))\n\t\t};\n\t}\n\n\t/**\n\t * Remove a rule group.\n\t * @param ruleGroupId The id of the rule group to remove.\n\t * @returns A promise that resolves when the rule group has been removed.\n\t */\n\tpublic async ruleGroupRemove(ruleGroupId: string): Promise<void> {\n\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"ruleGroupId\", ruleGroupId);\n\n\t\tconst extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);\n\n\t\tif (Is.empty(extractRuleGroup)) {\n\t\t\tthrow new NotFoundError(DataProcessingService.CLASS_NAME, \"ruleGroupNotFound\", ruleGroupId);\n\t\t}\n\n\t\tawait this._extractionRuleGroupStorage.remove(ruleGroupId);\n\t}\n\n\t/**\n\t * Extracts data from the provided input.\n\t * @param ruleGroupId The id of the rule group to use to extract data.\n\t * @param data The data to extract from.\n\t * @param overrideExtractorType An optional override for the extractor type.\n\t * @param overrideMimeType An optional override for the mime type for conversion, will auto detect if not provided.\n\t * @returns The extracted data.\n\t */\n\tpublic async extract(\n\t\truleGroupId: string,\n\t\tdata: Uint8Array,\n\t\toverrideExtractorType?: string,\n\t\toverrideMimeType?: string\n\t): Promise<unknown> {\n\t\tGuards.stringValue(DataProcessingService.CLASS_NAME, \"ruleGroupId\", ruleGroupId);\n\t\tGuards.uint8Array(DataProcessingService.CLASS_NAME, \"data\", data);\n\n\t\tconst extractRuleGroup = await this._extractionRuleGroupStorage.get(ruleGroupId);\n\n\t\tif (Is.empty(extractRuleGroup)) {\n\t\t\tthrow new NotFoundError(DataProcessingService.CLASS_NAME, \"ruleGroupNotFound\", ruleGroupId);\n\t\t}\n\n\t\tconst converted = await this.convert(data, overrideMimeType);\n\n\t\tconst extractor = Is.empty(overrideExtractorType)\n\t\t\t? this._extractorConnector\n\t\t\t: DataExtractorConnectorFactory.get(overrideExtractorType);\n\n\t\tconst extracted = await extractor.extract(converted, extractRuleGroup.rules);\n\t\treturn ObjectHelper.toExtended(extracted);\n\t}\n\n\t/**\n\t * Converts data from the provided input to a structured JSON document.\n\t * @param data The data to convert.\n\t * @param overrideMimeType An optional override for the mime type, will auto detect if empty.\n\t * @returns The converted data.\n\t */\n\tpublic async convert(data: Uint8Array, overrideMimeType?: string): Promise<unknown> {\n\t\tGuards.uint8Array(DataProcessingService.CLASS_NAME, \"data\", data);\n\n\t\tconst mimeType = overrideMimeType ?? (await MimeTypeHelper.detect(data));\n\t\tif (Is.empty(mimeType)) {\n\t\t\tthrow new GeneralError(DataProcessingService.CLASS_NAME, \"mimeTypeNotFound\");\n\t\t}\n\n\t\tconst converters = DataConverterConnectorFactory.instancesList();\n\n\t\tconst converter = converters.find(c => c.mimeTypes().includes(mimeType));\n\t\tif (Is.empty(converter)) {\n\t\t\tthrow new NotFoundError(DataProcessingService.CLASS_NAME, \"converterNotFound\", mimeType);\n\t\t}\n\n\t\treturn converter.convert(data);\n\t}\n\n\t/**\n\t * Query the rule group entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: IRuleGroup[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst result = await this._extractionRuleGroupStorage.query(\n\t\t\tundefined,\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tproperty: \"id\",\n\t\t\t\t\tsortDirection: SortDirection.Descending\n\t\t\t\t}\n\t\t\t],\n\t\t\tundefined,\n\t\t\tcursor,\n\t\t\tlimit\n\t\t);\n\n\t\treturn {\n\t\t\tentities: result.entities as IRuleGroup[],\n\t\t\tcursor: result.cursor\n\t\t};\n\t}\n}\n"]}
@@ -0,0 +1,43 @@
1
+ import { entity, property } from "@3sixty/entity";
2
+ /**
3
+ * Class defining an extraction rule.
4
+ */
5
+ let ExtractionRule = class ExtractionRule {
6
+ /**
7
+ * The JSONPath expression identifying the source field in the input document.
8
+ */
9
+ source;
10
+ /**
11
+ * The dotted path identifying where to store the extracted value in the output.
12
+ */
13
+ target;
14
+ /**
15
+ * The number of path segments from the source location to preserve in the target path.
16
+ */
17
+ retainPathDepth;
18
+ /**
19
+ * The type to coerce the extracted value to.
20
+ */
21
+ coerce;
22
+ };
23
+ __decorate([
24
+ property({ type: "string", maxLength: 2048 }),
25
+ __metadata("design:type", String)
26
+ ], ExtractionRule.prototype, "source", void 0);
27
+ __decorate([
28
+ property({ type: "string", maxLength: 2048 }),
29
+ __metadata("design:type", String)
30
+ ], ExtractionRule.prototype, "target", void 0);
31
+ __decorate([
32
+ property({ type: "number", optional: true }),
33
+ __metadata("design:type", Number)
34
+ ], ExtractionRule.prototype, "retainPathDepth", void 0);
35
+ __decorate([
36
+ property({ type: "string", maxLength: 16, optional: true }),
37
+ __metadata("design:type", String)
38
+ ], ExtractionRule.prototype, "coerce", void 0);
39
+ ExtractionRule = __decorate([
40
+ entity()
41
+ ], ExtractionRule);
42
+ export { ExtractionRule };
43
+ //# sourceMappingURL=extractionRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractionRule.js","sources":["../../../src/entities/extractionRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAC1B;;OAEG;IAEI,MAAM,CAAU;IAEvB;;OAEG;IAEI,MAAM,CAAU;IAEvB;;OAEG;IAEI,eAAe,CAAU;IAEhC;;OAEG;IAEI,MAAM,CAAc;CAC3B,CAAA;AAnBO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;8CACvB;AAMhB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;8CACvB;AAMhB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uDACb;AAMzB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACjC;AAvBf,cAAc;IAD1B,MAAM,EAAE;GACI,cAAc,CAwB1B","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { CoerceType } from \"@3sixty/core\";\nimport { entity, property } from \"@3sixty/entity\";\n\n/**\n * Class defining an extraction rule.\n */\n@entity()\nexport class ExtractionRule {\n\t/**\n\t * The JSONPath expression identifying the source field in the input document.\n\t */\n\t@property({ type: \"string\", maxLength: 2048 })\n\tpublic source!: string;\n\n\t/**\n\t * The dotted path identifying where to store the extracted value in the output.\n\t */\n\t@property({ type: \"string\", maxLength: 2048 })\n\tpublic target!: string;\n\n\t/**\n\t * The number of path segments from the source location to preserve in the target path.\n\t */\n\t@property({ type: \"number\", optional: true })\n\tpublic retainPathDepth?: number;\n\n\t/**\n\t * The type to coerce the extracted value to.\n\t */\n\t@property({ type: \"string\", maxLength: 16, optional: true })\n\tpublic coerce?: CoerceType;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { entity, property } from "@3sixty/entity";
4
+ /**
5
+ * Class defining an extraction rule group.
6
+ */
7
+ let ExtractionRuleGroup = class ExtractionRuleGroup {
8
+ /**
9
+ * The unique identifier for the rule group.
10
+ */
11
+ id;
12
+ /**
13
+ * The human-readable label for the rule group.
14
+ */
15
+ label;
16
+ /**
17
+ * The extraction rules that belong to this group.
18
+ */
19
+ rules;
20
+ };
21
+ __decorate([
22
+ property({ type: "string", isPrimary: true, maxLength: 255 }),
23
+ __metadata("design:type", String)
24
+ ], ExtractionRuleGroup.prototype, "id", void 0);
25
+ __decorate([
26
+ property({ type: "string", maxLength: 256 }),
27
+ __metadata("design:type", String)
28
+ ], ExtractionRuleGroup.prototype, "label", void 0);
29
+ __decorate([
30
+ property({ type: "array", itemTypeRef: "ExtractionRule", itemType: "object" }),
31
+ __metadata("design:type", Array)
32
+ ], ExtractionRuleGroup.prototype, "rules", void 0);
33
+ ExtractionRuleGroup = __decorate([
34
+ entity()
35
+ ], ExtractionRuleGroup);
36
+ export { ExtractionRuleGroup };
37
+ //# sourceMappingURL=extractionRuleGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractionRuleGroup.js","sources":["../../../src/entities/extractionRuleGroup.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;GAEG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC/B;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,KAAK,CAAU;IAEtB;;OAEG;IAEI,KAAK,CAAoB;CAChC,CAAA;AAbO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;;+CAC3C;AAMZ;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;;kDACvB;AAMf;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;;kDAC/C;AAjBpB,mBAAmB;IAD/B,MAAM,EAAE;GACI,mBAAmB,CAkB/B","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property } from \"@3sixty/entity\";\nimport type { ExtractionRule } from \"./extractionRule.js\";\n\n/**\n * Class defining an extraction rule group.\n */\n@entity()\nexport class ExtractionRuleGroup {\n\t/**\n\t * The unique identifier for the rule group.\n\t */\n\t@property({ type: \"string\", isPrimary: true, maxLength: 255 })\n\tpublic id!: string;\n\n\t/**\n\t * The human-readable label for the rule group.\n\t */\n\t@property({ type: \"string\", maxLength: 256 })\n\tpublic label!: string;\n\n\t/**\n\t * The extraction rules that belong to this group.\n\t */\n\t@property({ type: \"array\", itemTypeRef: \"ExtractionRule\", itemType: \"object\" })\n\tpublic rules!: ExtractionRule[];\n}\n"]}
@@ -0,0 +1,10 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./dataProcessingRoutes.js";
4
+ export * from "./dataProcessingService.js";
5
+ export * from "./entities/extractionRule.js";
6
+ export * from "./entities/extractionRuleGroup.js";
7
+ export * from "./models/IDataProcessingServiceConstructorOptions.js";
8
+ export * from "./restEntryPoints.js";
9
+ export * from "./schema.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sDAAsD,CAAC;AACrE,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./dataProcessingRoutes.js\";\nexport * from \"./dataProcessingService.js\";\nexport * from \"./entities/extractionRule.js\";\nexport * from \"./entities/extractionRuleGroup.js\";\nexport * from \"./models/IDataProcessingServiceConstructorOptions.js\";\nexport * from \"./restEntryPoints.js\";\nexport * from \"./schema.js\";\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IDataProcessingServiceConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IDataProcessingServiceConstructorOptions.js","sources":["../../../src/models/IDataProcessingServiceConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the data processing service constructor.\n */\nexport interface IDataProcessingServiceConstructorOptions {\n\t/**\n\t * The type of the entity storage connector to use for extraction rule groups.\n\t * @default extraction-rule-group\n\t */\n\textractionRuleGroupStorageConnectorType?: string;\n\n\t/**\n\t * The default extractor type to use, if not provided uses the first in the factory.\n\t */\n\tdefaultExtractorType?: string;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { generateRestRoutesDataProcessing, tagsDataProcessing } from "./dataProcessingRoutes.js";
2
+ /**
3
+ * The REST entry points for the data processing service.
4
+ */
5
+ export const restEntryPoints = [
6
+ {
7
+ name: "data-processing",
8
+ defaultBaseRoute: "data-processing",
9
+ tags: tagsDataProcessing,
10
+ generateRoutes: generateRestRoutesDataProcessing
11
+ }
12
+ ];
13
+ //# sourceMappingURL=restEntryPoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restEntryPoints.js","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gCAAgC,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEjG;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,iBAAiB;QACvB,gBAAgB,EAAE,iBAAiB;QACnC,IAAI,EAAE,kBAAkB;QACxB,cAAc,EAAE,gCAAgC;KAChD;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@3sixty/api-models\";\nimport { generateRestRoutesDataProcessing, tagsDataProcessing } from \"./dataProcessingRoutes.js\";\n\n/**\n * The REST entry points for the data processing service.\n */\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"data-processing\",\n\t\tdefaultBaseRoute: \"data-processing\",\n\t\ttags: tagsDataProcessing,\n\t\tgenerateRoutes: generateRestRoutesDataProcessing\n\t}\n];\n"]}
@@ -0,0 +1,13 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { EntitySchemaFactory, EntitySchemaHelper } from "@3sixty/entity";
4
+ import { ExtractionRule } from "./entities/extractionRule.js";
5
+ import { ExtractionRuleGroup } from "./entities/extractionRuleGroup.js";
6
+ /**
7
+ * Registers entity schemas for the data extraction connector entity storage.
8
+ */
9
+ export function initSchema() {
10
+ EntitySchemaFactory.register("ExtractionRuleGroup", () => EntitySchemaHelper.getSchema(ExtractionRuleGroup));
11
+ EntitySchemaFactory.register("ExtractionRule", () => EntitySchemaHelper.getSchema(ExtractionRule));
12
+ }
13
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,mBAAmB,CAAC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE,CACxD,kBAAkB,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACjD,CAAC;IACF,mBAAmB,CAAC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE,CACnD,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,CAC5C,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { EntitySchemaFactory, EntitySchemaHelper } from \"@3sixty/entity\";\n\nimport { ExtractionRule } from \"./entities/extractionRule.js\";\nimport { ExtractionRuleGroup } from \"./entities/extractionRuleGroup.js\";\n\n/**\n * Registers entity schemas for the data extraction connector entity storage.\n */\nexport function initSchema(): void {\n\tEntitySchemaFactory.register(\"ExtractionRuleGroup\", () =>\n\t\tEntitySchemaHelper.getSchema(ExtractionRuleGroup)\n\t);\n\tEntitySchemaFactory.register(\"ExtractionRule\", () =>\n\t\tEntitySchemaHelper.getSchema(ExtractionRule)\n\t);\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import { type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@3sixty/api-models";
2
+ import type { IDataProcessingConvertRequest, IDataProcessingConvertResponse, IDataProcessingExtractRequest, IDataProcessingExtractResponse, IDataProcessingRuleGroupGetRequest, IDataProcessingRuleGroupGetResponse, IDataProcessingRuleGroupListRequest, IDataProcessingRuleGroupListResponse, IDataProcessingRuleGroupRemoveRequest, IDataProcessingRuleGroupSetRequest } from "@3sixty/data-processing-models";
3
+ /**
4
+ * The tag to associate with the routes.
5
+ */
6
+ export declare const tagsDataProcessing: ITag[];
7
+ /**
8
+ * The REST routes for data processing.
9
+ * @param baseRouteName Prefix to prepend to the paths.
10
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
11
+ * @returns The generated routes.
12
+ */
13
+ export declare function generateRestRoutesDataProcessing(baseRouteName: string, componentName: string): IRestRoute[];
14
+ /**
15
+ * Store an extraction rule group.
16
+ * @param httpRequestContext The request context for the API.
17
+ * @param componentName The name of the component to use in the routes.
18
+ * @param request The request.
19
+ * @returns The response object with additional http response properties.
20
+ */
21
+ export declare function dataProcessingSetRuleGroup(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingRuleGroupSetRequest): Promise<INoContentResponse>;
22
+ /**
23
+ * Get an extraction rule group.
24
+ * @param httpRequestContext The request context for the API.
25
+ * @param componentName The name of the component to use in the routes.
26
+ * @param request The request.
27
+ * @returns The response object with additional http response properties.
28
+ */
29
+ export declare function dataProcessingGetRuleGroup(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingRuleGroupGetRequest): Promise<IDataProcessingRuleGroupGetResponse>;
30
+ /**
31
+ * Remove an extraction rule group.
32
+ * @param httpRequestContext The request context for the API.
33
+ * @param componentName The name of the component to use in the routes.
34
+ * @param request The request.
35
+ * @returns The response object with additional http response properties.
36
+ */
37
+ export declare function dataProcessingRemoveRuleGroup(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingRuleGroupRemoveRequest): Promise<INoContentResponse>;
38
+ /**
39
+ * Extract data using the specified rule group.
40
+ * @param httpRequestContext The request context for the API.
41
+ * @param componentName The name of the component to use in the routes.
42
+ * @param request The request.
43
+ * @returns The response object with additional http response properties.
44
+ */
45
+ export declare function dataProcessingExtract(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingExtractRequest): Promise<IDataProcessingExtractResponse>;
46
+ /**
47
+ * Convert data using the specified rule group.
48
+ * @param httpRequestContext The request context for the API.
49
+ * @param componentName The name of the component to use in the routes.
50
+ * @param request The request.
51
+ * @returns The response object with additional http response properties.
52
+ */
53
+ export declare function dataProcessingConvert(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingConvertRequest): Promise<IDataProcessingConvertResponse>;
54
+ /**
55
+ * Get a list of the rule group entries.
56
+ * @param httpRequestContext The request context for the API.
57
+ * @param componentName The name of the component to use in the routes.
58
+ * @param request The request.
59
+ * @returns The response object with additional http response properties.
60
+ */
61
+ export declare function ruleGroupList(httpRequestContext: IHttpRequestContext, componentName: string, request: IDataProcessingRuleGroupListRequest): Promise<IDataProcessingRuleGroupListResponse>;
@@ -0,0 +1,73 @@
1
+ import { type IDataProcessingComponent, type IRuleGroup } from "@3sixty/data-processing-models";
2
+ import type { IDataProcessingServiceConstructorOptions } from "./models/IDataProcessingServiceConstructorOptions.js";
3
+ /**
4
+ * Class for processing data from a source.
5
+ */
6
+ export declare class DataProcessingService implements IDataProcessingComponent {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * Create a new instance of DataExtractionService.
13
+ * @param options The options for the connector.
14
+ * @throws GeneralError If no extractor connector is registered.
15
+ */
16
+ constructor(options?: IDataProcessingServiceConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * Set an extraction rule group.
24
+ * @param ruleGroup The rule group to store.
25
+ * @returns A promise that resolves when the rule group has been stored.
26
+ */
27
+ ruleGroupSet(ruleGroup: IRuleGroup): Promise<void>;
28
+ /**
29
+ * Get a rule group for extraction.
30
+ * @param ruleGroupId The id of the rule group to get.
31
+ * @returns The rule group.
32
+ */
33
+ ruleGroupGet(ruleGroupId: string): Promise<IRuleGroup>;
34
+ /**
35
+ * Remove a rule group.
36
+ * @param ruleGroupId The id of the rule group to remove.
37
+ * @returns A promise that resolves when the rule group has been removed.
38
+ */
39
+ ruleGroupRemove(ruleGroupId: string): Promise<void>;
40
+ /**
41
+ * Extracts data from the provided input.
42
+ * @param ruleGroupId The id of the rule group to use to extract data.
43
+ * @param data The data to extract from.
44
+ * @param overrideExtractorType An optional override for the extractor type.
45
+ * @param overrideMimeType An optional override for the mime type for conversion, will auto detect if not provided.
46
+ * @returns The extracted data.
47
+ */
48
+ extract(ruleGroupId: string, data: Uint8Array, overrideExtractorType?: string, overrideMimeType?: string): Promise<unknown>;
49
+ /**
50
+ * Converts data from the provided input to a structured JSON document.
51
+ * @param data The data to convert.
52
+ * @param overrideMimeType An optional override for the mime type, will auto detect if empty.
53
+ * @returns The converted data.
54
+ */
55
+ convert(data: Uint8Array, overrideMimeType?: string): Promise<unknown>;
56
+ /**
57
+ * Query the rule group entries.
58
+ * @param cursor The cursor to request the next chunk of entities.
59
+ * @param limit Limit the number of entities to return.
60
+ * @returns All the entities for the storage matching the conditions,
61
+ * and a cursor which can be used to request more entities.
62
+ */
63
+ query(cursor?: string, limit?: number): Promise<{
64
+ /**
65
+ * The entities, which can be partial if a limited keys list was provided.
66
+ */
67
+ entities: IRuleGroup[];
68
+ /**
69
+ * An optional cursor, when defined can be used to call find to get more entities.
70
+ */
71
+ cursor?: string;
72
+ }>;
73
+ }
@@ -0,0 +1,22 @@
1
+ import type { CoerceType } from "@3sixty/core";
2
+ /**
3
+ * Class defining an extraction rule.
4
+ */
5
+ export declare class ExtractionRule {
6
+ /**
7
+ * The JSONPath expression identifying the source field in the input document.
8
+ */
9
+ source: string;
10
+ /**
11
+ * The dotted path identifying where to store the extracted value in the output.
12
+ */
13
+ target: string;
14
+ /**
15
+ * The number of path segments from the source location to preserve in the target path.
16
+ */
17
+ retainPathDepth?: number;
18
+ /**
19
+ * The type to coerce the extracted value to.
20
+ */
21
+ coerce?: CoerceType;
22
+ }
@@ -0,0 +1,18 @@
1
+ import type { ExtractionRule } from "./extractionRule.js";
2
+ /**
3
+ * Class defining an extraction rule group.
4
+ */
5
+ export declare class ExtractionRuleGroup {
6
+ /**
7
+ * The unique identifier for the rule group.
8
+ */
9
+ id: string;
10
+ /**
11
+ * The human-readable label for the rule group.
12
+ */
13
+ label: string;
14
+ /**
15
+ * The extraction rules that belong to this group.
16
+ */
17
+ rules: ExtractionRule[];
18
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./dataProcessingRoutes.js";
2
+ export * from "./dataProcessingService.js";
3
+ export * from "./entities/extractionRule.js";
4
+ export * from "./entities/extractionRuleGroup.js";
5
+ export * from "./models/IDataProcessingServiceConstructorOptions.js";
6
+ export * from "./restEntryPoints.js";
7
+ export * from "./schema.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The options for the data processing service constructor.
3
+ */
4
+ export interface IDataProcessingServiceConstructorOptions {
5
+ /**
6
+ * The type of the entity storage connector to use for extraction rule groups.
7
+ * @default extraction-rule-group
8
+ */
9
+ extractionRuleGroupStorageConnectorType?: string;
10
+ /**
11
+ * The default extractor type to use, if not provided uses the first in the factory.
12
+ */
13
+ defaultExtractorType?: string;
14
+ }
@@ -0,0 +1,5 @@
1
+ import type { IRestRouteEntryPoint } from "@3sixty/api-models";
2
+ /**
3
+ * The REST entry points for the data processing service.
4
+ */
5
+ export declare const restEntryPoints: IRestRouteEntryPoint[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Registers entity schemas for the data extraction connector entity storage.
3
+ */
4
+ export declare function initSchema(): void;
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.20.0-next.1](https://github.com/3sixtyglobal/data-processing/compare/data-processing-service-v0.20.0-next.0...data-processing-service-v0.20.0-next.1) (2026-10-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * publish packages under the [@3sixty](https://github.com/3sixty) namespace ([e62a15f](https://github.com/3sixtyglobal/data-processing/commit/e62a15f0f619ee7161c1f881a10a2d7db48dbc4d))
9
+ * updated ts compile ([ba5bfb7](https://github.com/3sixtyglobal/data-processing/commit/ba5bfb7ce9fa96b17952fe0074192e73ccb4b1d6))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @3sixty/data-processing-models bumped from 0.20.0-next.0 to 0.20.0-next.1
17
+ * devDependencies
18
+ * @3sixty/data-processing-converters bumped from 0.20.0-next.0 to 0.20.0-next.1
19
+ * @3sixty/data-processing-extractors bumped from 0.20.0-next.0 to 0.20.0-next.1