@lbdudc/linea-core 0.1.0
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/README.md +358 -0
- package/dist/analysis/analyze.d.ts +105 -0
- package/dist/analysis/analyze.js +220 -0
- package/dist/analysis/analyze.js.map +1 -0
- package/dist/analysis/runtime.d.ts +97 -0
- package/dist/analysis/runtime.js +198 -0
- package/dist/analysis/runtime.js.map +1 -0
- package/dist/analysis/wheels/micropip-0.6.0-py3-none-any.whl +0 -0
- package/dist/analysis/wheels/packaging-23.2-py3-none-any.whl +0 -0
- package/dist/assets.d.ts +16 -0
- package/dist/assets.js +36 -0
- package/dist/assets.js.map +1 -0
- package/dist/constants.d.ts +77 -0
- package/dist/constants.js +76 -0
- package/dist/constants.js.map +1 -0
- package/dist/derivation/derive.d.ts +68 -0
- package/dist/derivation/derive.js +115 -0
- package/dist/derivation/derive.js.map +1 -0
- package/dist/derivation/engine.d.ts +48 -0
- package/dist/derivation/engine.js +98 -0
- package/dist/derivation/engine.js.map +1 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/feature-model/convert.d.ts +35 -0
- package/dist/feature-model/convert.js +47 -0
- package/dist/feature-model/convert.js.map +1 -0
- package/dist/feature-model/engine.d.ts +60 -0
- package/dist/feature-model/engine.js +139 -0
- package/dist/feature-model/engine.js.map +1 -0
- package/dist/feature-model/inspect.d.ts +67 -0
- package/dist/feature-model/inspect.js +113 -0
- package/dist/feature-model/inspect.js.map +1 -0
- package/dist/feature-model/io.d.ts +66 -0
- package/dist/feature-model/io.js +92 -0
- package/dist/feature-model/io.js.map +1 -0
- package/dist/feature-model/parse.d.ts +30 -0
- package/dist/feature-model/parse.js +36 -0
- package/dist/feature-model/parse.js.map +1 -0
- package/dist/feature-model/text.d.ts +54 -0
- package/dist/feature-model/text.js +126 -0
- package/dist/feature-model/text.js.map +1 -0
- package/dist/fs/archive.d.ts +23 -0
- package/dist/fs/archive.js +87 -0
- package/dist/fs/archive.js.map +1 -0
- package/dist/fs/diff.d.ts +40 -0
- package/dist/fs/diff.js +155 -0
- package/dist/fs/diff.js.map +1 -0
- package/dist/fs/format.d.ts +21 -0
- package/dist/fs/format.js +111 -0
- package/dist/fs/format.js.map +1 -0
- package/dist/fs/workspace.d.ts +77 -0
- package/dist/fs/workspace.js +103 -0
- package/dist/fs/workspace.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/guards.d.ts +15 -0
- package/dist/internal/guards.js +16 -0
- package/dist/internal/guards.js.map +1 -0
- package/dist/line/platform-files.d.ts +73 -0
- package/dist/line/platform-files.js +112 -0
- package/dist/line/platform-files.js.map +1 -0
- package/dist/line/scaffold.d.ts +88 -0
- package/dist/line/scaffold.js +145 -0
- package/dist/line/scaffold.js.map +1 -0
- package/dist/line/templates/core/extra.js +54 -0
- package/dist/line/templates/core/transformation.js +196 -0
- package/dist/line/templates/metamodels/dataModel/extra.js +328 -0
- package/dist/line/templates/metamodels/dataModel/transformation.js +211 -0
- package/dist/line/templates/metamodels/sensor/extra.js +36 -0
- package/dist/line/templates/metamodels/sensor/transformation.js +47 -0
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -0
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -0
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -0
- package/dist/product/engine-spec.d.ts +25 -0
- package/dist/product/engine-spec.js +77 -0
- package/dist/product/engine-spec.js.map +1 -0
- package/dist/product/spec.d.ts +130 -0
- package/dist/product/spec.js +219 -0
- package/dist/product/spec.js.map +1 -0
- package/dist/product/version.d.ts +27 -0
- package/dist/product/version.js +49 -0
- package/dist/product/version.js.map +1 -0
- package/dist/products-index/products-index.d.ts +224 -0
- package/dist/products-index/products-index.js +395 -0
- package/dist/products-index/products-index.js.map +1 -0
- package/dist/selection/selection.d.ts +126 -0
- package/dist/selection/selection.js +152 -0
- package/dist/selection/selection.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProductSpec } from './spec.js';
|
|
2
|
+
/** A spec in the engine's shortcut shape. */
|
|
3
|
+
export interface EngineSpec {
|
|
4
|
+
features: string[];
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.
|
|
10
|
+
*
|
|
11
|
+
* Returns the input spec **by reference** when there is no sensor shortcut to
|
|
12
|
+
* apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts
|
|
13
|
+
* identity with `toBe(spec)`, so that is contractual, not incidental.
|
|
14
|
+
*
|
|
15
|
+
* The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and
|
|
16
|
+
* `data.basicData`. In that case `database` and `version` are carried over from
|
|
17
|
+
* the product's own `basicData`, with `database` defaulting to `{}`.
|
|
18
|
+
*
|
|
19
|
+
* @param params.spec The product spec.
|
|
20
|
+
* @returns Either the same spec, or a new object in the engine shortcut shape.
|
|
21
|
+
* @throws {InvalidArgumentError} when `spec` is not an object.
|
|
22
|
+
*/
|
|
23
|
+
export declare const buildEngineSpec: ({ spec }: {
|
|
24
|
+
spec: ProductSpec;
|
|
25
|
+
}) => ProductSpec | EngineSpec;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts a product spec to the shape `spl-js-engine` expects.
|
|
3
|
+
*
|
|
4
|
+
* HARDENED PORT of
|
|
5
|
+
* `linea/server/src/model/services/generatePipeline.js:buildEngineSpec` (~34-50).
|
|
6
|
+
* The original guards the shortcut with plain truthiness
|
|
7
|
+
* (`parsed?.features && parsed?.data?.basicData`), so a spec with
|
|
8
|
+
* `sensor.parsed.features = 'ABC'` takes the shortcut and hands the engine a
|
|
9
|
+
* string where it expects an array. Here the checks are `Array.isArray` and
|
|
10
|
+
* `isPlainObject`, so such a spec passes through untouched instead.
|
|
11
|
+
* Its comment explains the intent: when a product carries a parsed sensor DSL,
|
|
12
|
+
* pipe it straight to the engine's shortcut path, which activates when both
|
|
13
|
+
* `input.data` and `input.data.basicData` are present (see the mock platform's
|
|
14
|
+
* `transformation.js:modelTransformation`). Otherwise the spec passes through.
|
|
15
|
+
*
|
|
16
|
+
* The sensor DSL itself is out of scope for linea-core in this batch; this
|
|
17
|
+
* function only routes an ALREADY parsed `sensor.parsed` payload, which is why it
|
|
18
|
+
* needs no DSL dependency.
|
|
19
|
+
*/
|
|
20
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
21
|
+
import { isPlainObject } from '../internal/guards.js';
|
|
22
|
+
/**
|
|
23
|
+
* Reproduces the monolith's `spec.basicData?.database || {}`.
|
|
24
|
+
*
|
|
25
|
+
* `??` would NOT be equivalent: `||` also replaces falsy non-nullish values
|
|
26
|
+
* (`''`, `0`, `0n`, `false`, `NaN`). The schema types `database` as an Object so
|
|
27
|
+
* the difference is unreachable in practice, but parity is parity and a silent
|
|
28
|
+
* behaviour change here would be invisible until a generation produced the wrong
|
|
29
|
+
* config. Written as a ternary on the value itself, which IS `||` by definition
|
|
30
|
+
* and therefore cannot drift from it.
|
|
31
|
+
*/
|
|
32
|
+
// NOTE: `??` is precisely the WRONG operator here. The monolith uses `||`, so
|
|
33
|
+
// falsy non-nullish values must fall back too; that is the entire point of this
|
|
34
|
+
// helper, and the lint rule cannot know it.
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
36
|
+
const truthyOr = (value, fallback) => (value ? value : fallback);
|
|
37
|
+
/**
|
|
38
|
+
* Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.
|
|
39
|
+
*
|
|
40
|
+
* Returns the input spec **by reference** when there is no sensor shortcut to
|
|
41
|
+
* apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts
|
|
42
|
+
* identity with `toBe(spec)`, so that is contractual, not incidental.
|
|
43
|
+
*
|
|
44
|
+
* The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and
|
|
45
|
+
* `data.basicData`. In that case `database` and `version` are carried over from
|
|
46
|
+
* the product's own `basicData`, with `database` defaulting to `{}`.
|
|
47
|
+
*
|
|
48
|
+
* @param params.spec The product spec.
|
|
49
|
+
* @returns Either the same spec, or a new object in the engine shortcut shape.
|
|
50
|
+
* @throws {InvalidArgumentError} when `spec` is not an object.
|
|
51
|
+
*/
|
|
52
|
+
export const buildEngineSpec = ({ spec }) => {
|
|
53
|
+
if (!isPlainObject(spec)) {
|
|
54
|
+
throw new InvalidArgumentError('"spec" must be an object.');
|
|
55
|
+
}
|
|
56
|
+
const parsed = isPlainObject(spec.sensor) ? spec.sensor.parsed : undefined;
|
|
57
|
+
if (!isPlainObject(parsed))
|
|
58
|
+
return spec;
|
|
59
|
+
const parsedData = isPlainObject(parsed.data) ? parsed.data : undefined;
|
|
60
|
+
if (!Array.isArray(parsed.features) || !isPlainObject(parsedData?.basicData))
|
|
61
|
+
return spec;
|
|
62
|
+
const specBasicData = isPlainObject(spec.basicData) ? spec.basicData : undefined;
|
|
63
|
+
return {
|
|
64
|
+
features: parsed.features,
|
|
65
|
+
data: {
|
|
66
|
+
...parsedData,
|
|
67
|
+
basicData: {
|
|
68
|
+
...parsedData.basicData,
|
|
69
|
+
database: truthyOr(specBasicData?.database, {}),
|
|
70
|
+
// No default: the monolith passes `spec.basicData?.version` straight
|
|
71
|
+
// through, so an absent version stays `undefined`.
|
|
72
|
+
version: specBasicData?.version
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=engine-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-spec.js","sourceRoot":"","sources":["../../src/product/engine-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,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AC,SAAS;gBACvB,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC;gBAC/C,qEAAqE;gBACrE,mDAAmD;gBACnD,OAAO,EAAE,aAAa,EAAE,OAAO;aAChC;SACF;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Adapts a product spec to the shape `spl-js-engine` expects.\r\n *\r\n * HARDENED PORT of\r\n * `linea/server/src/model/services/generatePipeline.js:buildEngineSpec` (~34-50).\r\n * The original guards the shortcut with plain truthiness\r\n * (`parsed?.features && parsed?.data?.basicData`), so a spec with\r\n * `sensor.parsed.features = 'ABC'` takes the shortcut and hands the engine a\r\n * string where it expects an array. Here the checks are `Array.isArray` and\r\n * `isPlainObject`, so such a spec passes through untouched instead.\r\n * Its comment explains the intent: when a product carries a parsed sensor DSL,\r\n * pipe it straight to the engine's shortcut path, which activates when both\r\n * `input.data` and `input.data.basicData` are present (see the mock platform's\r\n * `transformation.js:modelTransformation`). Otherwise the spec passes through.\r\n *\r\n * The sensor DSL itself is out of scope for linea-core in this batch; this\r\n * function only routes an ALREADY parsed `sensor.parsed` payload, which is why it\r\n * needs no DSL dependency.\r\n */\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { isPlainObject } from '../internal/guards.js'\r\nimport type { ProductSpec } from './spec.js'\r\n\r\n/** A spec in the engine's shortcut shape. */\r\nexport interface EngineSpec {\r\n features: string[]\r\n data: Record<string, unknown>\r\n [key: string]: unknown\r\n}\r\n\r\n/**\r\n * Reproduces the monolith's `spec.basicData?.database || {}`.\r\n *\r\n * `??` would NOT be equivalent: `||` also replaces falsy non-nullish values\r\n * (`''`, `0`, `0n`, `false`, `NaN`). The schema types `database` as an Object so\r\n * the difference is unreachable in practice, but parity is parity and a silent\r\n * behaviour change here would be invisible until a generation produced the wrong\r\n * config. Written as a ternary on the value itself, which IS `||` by definition\r\n * and therefore cannot drift from it.\r\n */\r\n// NOTE: `??` is precisely the WRONG operator here. The monolith uses `||`, so\r\n// falsy non-nullish values must fall back too; that is the entire point of this\r\n// helper, and the lint rule cannot know it.\r\n// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\r\nconst truthyOr = (value: unknown, fallback: unknown): unknown => (value ? value : fallback)\r\n\r\n/**\r\n * Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.\r\n *\r\n * Returns the input spec **by reference** when there is no sensor shortcut to\r\n * apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts\r\n * identity with `toBe(spec)`, so that is contractual, not incidental.\r\n *\r\n * The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and\r\n * `data.basicData`. In that case `database` and `version` are carried over from\r\n * the product's own `basicData`, with `database` defaulting to `{}`.\r\n *\r\n * @param params.spec The product spec.\r\n * @returns Either the same spec, or a new object in the engine shortcut shape.\r\n * @throws {InvalidArgumentError} when `spec` is not an object.\r\n */\r\nexport const buildEngineSpec = ({ spec }: { spec: ProductSpec }): ProductSpec | EngineSpec => {\r\n if (!isPlainObject(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n\r\n const parsed = isPlainObject(spec.sensor) ? spec.sensor.parsed : undefined\r\n if (!isPlainObject(parsed)) return spec\r\n\r\n const parsedData = isPlainObject(parsed.data) ? parsed.data : undefined\r\n if (!Array.isArray(parsed.features) || !isPlainObject(parsedData?.basicData)) return spec\r\n\r\n const specBasicData = isPlainObject(spec.basicData) ? spec.basicData : undefined\r\n\r\n return {\r\n features: parsed.features as string[],\r\n data: {\r\n ...parsedData,\r\n basicData: {\r\n ...parsedData.basicData,\r\n database: truthyOr(specBasicData?.database, {}),\r\n // No default: the monolith passes `spec.basicData?.version` straight\r\n // through, so an absent version stays `undefined`.\r\n version: specBasicData?.version\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** `spec.basicData` — product identity and generation-wide settings. */
|
|
2
|
+
export interface ProductBasicData {
|
|
3
|
+
name?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
languages?: string[];
|
|
6
|
+
SRID?: string;
|
|
7
|
+
database?: Record<string, unknown>;
|
|
8
|
+
extra?: Record<string, unknown>;
|
|
9
|
+
testEnvironment?: {
|
|
10
|
+
image?: string;
|
|
11
|
+
command?: string;
|
|
12
|
+
};
|
|
13
|
+
createdAt?: unknown;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** A product spec as stored by the monolith and consumed by the engine. */
|
|
17
|
+
export interface ProductSpec {
|
|
18
|
+
basicData?: ProductBasicData;
|
|
19
|
+
dataModel?: {
|
|
20
|
+
cells?: unknown[];
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
features?: string[] | Record<string, boolean>;
|
|
24
|
+
statics?: unknown[];
|
|
25
|
+
sensor?: {
|
|
26
|
+
dsl?: string;
|
|
27
|
+
parsed?: unknown;
|
|
28
|
+
};
|
|
29
|
+
/** Legacy feature-selection field. */
|
|
30
|
+
selection?: string[];
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** A single spec problem. */
|
|
34
|
+
export interface ProductSpecError {
|
|
35
|
+
/** Dotted path of the offending field, e.g. `spec.basicData.name`. */
|
|
36
|
+
readonly path: string;
|
|
37
|
+
/** Stable machine-readable discriminator. */
|
|
38
|
+
readonly code: ProductSpecErrorCode;
|
|
39
|
+
/**
|
|
40
|
+
* An i18n KEY, never a human-readable sentence. Always pass it through the
|
|
41
|
+
* consumer's translation function; there is nothing sensible to render raw.
|
|
42
|
+
*
|
|
43
|
+
* Five keys are INHERITED verbatim from the monolith and already have
|
|
44
|
+
* translations in `linea/client/src/i18n/{en,es,gl}`:
|
|
45
|
+
* `spec_object_validation`, `basicData_object_validation`,
|
|
46
|
+
* `basicData_name_validation`, `invalid_name_characters`,
|
|
47
|
+
* `basicData_version_format`.
|
|
48
|
+
*
|
|
49
|
+
* Four keys are NEW and have NO translation yet, because the monolith enforced
|
|
50
|
+
* these constraints through the Mongoose schema rather than express-validator,
|
|
51
|
+
* so there was no key to copy: `basicData_languages_validation`,
|
|
52
|
+
* `basicData_SRID_validation`, `spec_features_validation`,
|
|
53
|
+
* `spec_statics_validation`. Until webui and linea-cli add them, vue-i18n will
|
|
54
|
+
* render the key itself. Tracked in CHANGELOG.md.
|
|
55
|
+
*/
|
|
56
|
+
readonly messageKey: string;
|
|
57
|
+
}
|
|
58
|
+
/** Stable discriminators for spec problems. */
|
|
59
|
+
export type ProductSpecErrorCode = 'SPEC_NOT_OBJECT' | 'BASIC_DATA_NOT_OBJECT' | 'NAME_REQUIRED' | 'NAME_INVALID_CHARACTERS' | 'VERSION_FORMAT' | 'LANGUAGES_NOT_STRING_ARRAY' | 'SRID_NOT_STRING' | 'FEATURES_INVALID_SHAPE' | 'STATICS_NOT_ARRAY';
|
|
60
|
+
/** Result of validating a spec. */
|
|
61
|
+
export interface ProductSpecValidation {
|
|
62
|
+
readonly valid: boolean;
|
|
63
|
+
readonly errors: ProductSpecError[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates a product spec **without throwing**.
|
|
67
|
+
*
|
|
68
|
+
* Reproduces `createProductValidator` / `updateProductValidator` with their exact
|
|
69
|
+
* i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema
|
|
70
|
+
* used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry
|
|
71
|
+
* new keys with no translation yet — see `ProductSpecError.messageKey`.
|
|
72
|
+
*
|
|
73
|
+
* `lineId` is NOT validated here: it is a GitLab/persistence concern that lives
|
|
74
|
+
* in linea-server (ADR-003), even though `createProductValidator` checks it.
|
|
75
|
+
*
|
|
76
|
+
* @param params.spec The spec to validate. Anything, including nullish.
|
|
77
|
+
* @returns `valid` plus one entry per problem, in a stable order.
|
|
78
|
+
*/
|
|
79
|
+
export declare const validateProductSpec: ({ spec }: {
|
|
80
|
+
spec: unknown;
|
|
81
|
+
}) => ProductSpecValidation;
|
|
82
|
+
/**
|
|
83
|
+
* Validates a product spec and throws when it is not acceptable.
|
|
84
|
+
*
|
|
85
|
+
* The throwing counterpart of `validateProductSpec`, mirroring the
|
|
86
|
+
* `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes
|
|
87
|
+
* `InvalidProductSpecError` reachable: the monolith's equivalent is
|
|
88
|
+
* express-validator short-circuiting the request with a 400 before
|
|
89
|
+
* `ProductService.createProduct` ever runs, which has no direct analogue in a
|
|
90
|
+
* library.
|
|
91
|
+
*
|
|
92
|
+
* The message lists every problem with its i18n key. Callers that need the
|
|
93
|
+
* problems as DATA (to build an HTTP response body, say) should call
|
|
94
|
+
* `validateProductSpec` instead — that is precisely what it is for, and it keeps
|
|
95
|
+
* this error free of ad-hoc payload properties.
|
|
96
|
+
*
|
|
97
|
+
* @param params.spec The spec to validate.
|
|
98
|
+
* @returns The spec, unchanged, when it is valid.
|
|
99
|
+
* @throws {InvalidProductSpecError} listing every problem found.
|
|
100
|
+
*/
|
|
101
|
+
export declare const assertProductSpec: ({ spec }: {
|
|
102
|
+
spec: ProductSpec;
|
|
103
|
+
}) => ProductSpec;
|
|
104
|
+
/**
|
|
105
|
+
* Fills a product spec with the domain defaults.
|
|
106
|
+
*
|
|
107
|
+
* Union of the two places the monolith applies defaults:
|
|
108
|
+
* - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,
|
|
109
|
+
* `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`
|
|
110
|
+
* `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,
|
|
111
|
+
* `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.
|
|
112
|
+
* - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies
|
|
113
|
+
* `database`, `extra`, `languages` and `SRID` with `||` right before returning.
|
|
114
|
+
*
|
|
115
|
+
* `||` semantics are preserved for those four, which is subtler than it looks:
|
|
116
|
+
* an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an
|
|
117
|
+
* EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.
|
|
118
|
+
*
|
|
119
|
+
* PURE: returns a new object and never mutates the input. `basicData.createdAt`
|
|
120
|
+
* is deliberately NOT filled — the schema defaults it to `Date.now`, which would
|
|
121
|
+
* make this function non-deterministic. Timestamping is persistence metadata and
|
|
122
|
+
* belongs to linea-server.
|
|
123
|
+
*
|
|
124
|
+
* @param params.spec The spec to complete.
|
|
125
|
+
* @returns A new spec with defaults applied.
|
|
126
|
+
* @throws {InvalidArgumentError} when `spec` is not an object.
|
|
127
|
+
*/
|
|
128
|
+
export declare const normalizeProductSpec: ({ spec }: {
|
|
129
|
+
spec: ProductSpec;
|
|
130
|
+
}) => ProductSpec;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Product spec validation and default filling.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from:
|
|
5
|
+
* - `linea/server/src/rest/validators/productValidators.js` (createProductValidator,
|
|
6
|
+
* updateProductValidator) and `commonValidators.js` (`nameRule`, `versionRule`)
|
|
7
|
+
* - `linea/server/src/model/entities/product.js` — the Mongoose schema defaults
|
|
8
|
+
* - `linea/server/src/model/services/generatePipeline.js:saveProductVersion`
|
|
9
|
+
* (~212-222) — the defaults applied right before returning a generated product
|
|
10
|
+
*
|
|
11
|
+
* The monolith validates at the HTTP edge with express-validator and fills
|
|
12
|
+
* defaults twice: once through the Mongoose schema and once again in
|
|
13
|
+
* `saveProductVersion`. Neither mechanism exists in linea-core, so both collapse
|
|
14
|
+
* into these two functions.
|
|
15
|
+
*
|
|
16
|
+
* `linea-cli/src/core/specSchema.ts` duplicates the same rules with Zod today and
|
|
17
|
+
* is meant to call this instead.
|
|
18
|
+
*/
|
|
19
|
+
import { DEFAULT_LANGUAGES, DEFAULT_SRID, NAME_PATTERN, VERSION_PATTERN } from '../constants.js';
|
|
20
|
+
import { InvalidArgumentError, InvalidProductSpecError } from '../errors.js';
|
|
21
|
+
import { isPlainObject } from '../internal/guards.js';
|
|
22
|
+
/**
|
|
23
|
+
* Validates a product spec **without throwing**.
|
|
24
|
+
*
|
|
25
|
+
* Reproduces `createProductValidator` / `updateProductValidator` with their exact
|
|
26
|
+
* i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema
|
|
27
|
+
* used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry
|
|
28
|
+
* new keys with no translation yet — see `ProductSpecError.messageKey`.
|
|
29
|
+
*
|
|
30
|
+
* `lineId` is NOT validated here: it is a GitLab/persistence concern that lives
|
|
31
|
+
* in linea-server (ADR-003), even though `createProductValidator` checks it.
|
|
32
|
+
*
|
|
33
|
+
* @param params.spec The spec to validate. Anything, including nullish.
|
|
34
|
+
* @returns `valid` plus one entry per problem, in a stable order.
|
|
35
|
+
*/
|
|
36
|
+
export const validateProductSpec = ({ spec }) => {
|
|
37
|
+
const errors = [];
|
|
38
|
+
if (!isPlainObject(spec)) {
|
|
39
|
+
return {
|
|
40
|
+
valid: false,
|
|
41
|
+
errors: [{
|
|
42
|
+
path: 'spec',
|
|
43
|
+
code: 'SPEC_NOT_OBJECT',
|
|
44
|
+
messageKey: 'error_messages.spec_object_validation'
|
|
45
|
+
}]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const basicData = spec.basicData;
|
|
49
|
+
if (!isPlainObject(basicData)) {
|
|
50
|
+
return {
|
|
51
|
+
valid: false,
|
|
52
|
+
errors: [{
|
|
53
|
+
path: 'spec.basicData',
|
|
54
|
+
code: 'BASIC_DATA_NOT_OBJECT',
|
|
55
|
+
messageKey: 'error_messages.basicData_object_validation'
|
|
56
|
+
}]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const name = basicData.name;
|
|
60
|
+
if (typeof name !== 'string' || name === '') {
|
|
61
|
+
errors.push({
|
|
62
|
+
path: 'spec.basicData.name',
|
|
63
|
+
code: 'NAME_REQUIRED',
|
|
64
|
+
messageKey: 'error_messages.basicData_name_validation'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (!NAME_PATTERN.test(name)) {
|
|
68
|
+
errors.push({
|
|
69
|
+
path: 'spec.basicData.name',
|
|
70
|
+
code: 'NAME_INVALID_CHARACTERS',
|
|
71
|
+
messageKey: 'error_messages.invalid_name_characters'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (typeof basicData.version !== 'string' || !VERSION_PATTERN.test(basicData.version)) {
|
|
75
|
+
errors.push({
|
|
76
|
+
path: 'spec.basicData.version',
|
|
77
|
+
code: 'VERSION_FORMAT',
|
|
78
|
+
messageKey: 'error_messages.basicData_version_format'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const { languages } = basicData;
|
|
82
|
+
if (languages !== undefined &&
|
|
83
|
+
(!Array.isArray(languages) || languages.some((l) => typeof l !== 'string'))) {
|
|
84
|
+
errors.push({
|
|
85
|
+
path: 'spec.basicData.languages',
|
|
86
|
+
code: 'LANGUAGES_NOT_STRING_ARRAY',
|
|
87
|
+
messageKey: 'error_messages.basicData_languages_validation'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (basicData.SRID !== undefined && typeof basicData.SRID !== 'string') {
|
|
91
|
+
errors.push({
|
|
92
|
+
path: 'spec.basicData.SRID',
|
|
93
|
+
code: 'SRID_NOT_STRING',
|
|
94
|
+
messageKey: 'error_messages.basicData_SRID_validation'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const { features } = spec;
|
|
98
|
+
const featuresValid = features === undefined ||
|
|
99
|
+
(Array.isArray(features) && features.every((f) => typeof f === 'string')) ||
|
|
100
|
+
isPlainObject(features);
|
|
101
|
+
if (!featuresValid) {
|
|
102
|
+
errors.push({
|
|
103
|
+
path: 'spec.features',
|
|
104
|
+
code: 'FEATURES_INVALID_SHAPE',
|
|
105
|
+
messageKey: 'error_messages.spec_features_validation'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (spec.statics !== undefined && !Array.isArray(spec.statics)) {
|
|
109
|
+
errors.push({
|
|
110
|
+
path: 'spec.statics',
|
|
111
|
+
code: 'STATICS_NOT_ARRAY',
|
|
112
|
+
messageKey: 'error_messages.spec_statics_validation'
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return { valid: errors.length === 0, errors };
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Validates a product spec and throws when it is not acceptable.
|
|
119
|
+
*
|
|
120
|
+
* The throwing counterpart of `validateProductSpec`, mirroring the
|
|
121
|
+
* `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes
|
|
122
|
+
* `InvalidProductSpecError` reachable: the monolith's equivalent is
|
|
123
|
+
* express-validator short-circuiting the request with a 400 before
|
|
124
|
+
* `ProductService.createProduct` ever runs, which has no direct analogue in a
|
|
125
|
+
* library.
|
|
126
|
+
*
|
|
127
|
+
* The message lists every problem with its i18n key. Callers that need the
|
|
128
|
+
* problems as DATA (to build an HTTP response body, say) should call
|
|
129
|
+
* `validateProductSpec` instead — that is precisely what it is for, and it keeps
|
|
130
|
+
* this error free of ad-hoc payload properties.
|
|
131
|
+
*
|
|
132
|
+
* @param params.spec The spec to validate.
|
|
133
|
+
* @returns The spec, unchanged, when it is valid.
|
|
134
|
+
* @throws {InvalidProductSpecError} listing every problem found.
|
|
135
|
+
*/
|
|
136
|
+
export const assertProductSpec = ({ spec }) => {
|
|
137
|
+
const { valid, errors } = validateProductSpec({ spec });
|
|
138
|
+
if (!valid) {
|
|
139
|
+
const summary = errors.map((error) => `${error.path}: ${error.messageKey}`).join('; ');
|
|
140
|
+
throw new InvalidProductSpecError(`Invalid product spec: ${summary}`);
|
|
141
|
+
}
|
|
142
|
+
return spec;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Fills a product spec with the domain defaults.
|
|
146
|
+
*
|
|
147
|
+
* Union of the two places the monolith applies defaults:
|
|
148
|
+
* - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,
|
|
149
|
+
* `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`
|
|
150
|
+
* `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,
|
|
151
|
+
* `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.
|
|
152
|
+
* - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies
|
|
153
|
+
* `database`, `extra`, `languages` and `SRID` with `||` right before returning.
|
|
154
|
+
*
|
|
155
|
+
* `||` semantics are preserved for those four, which is subtler than it looks:
|
|
156
|
+
* an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an
|
|
157
|
+
* EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.
|
|
158
|
+
*
|
|
159
|
+
* PURE: returns a new object and never mutates the input. `basicData.createdAt`
|
|
160
|
+
* is deliberately NOT filled — the schema defaults it to `Date.now`, which would
|
|
161
|
+
* make this function non-deterministic. Timestamping is persistence metadata and
|
|
162
|
+
* belongs to linea-server.
|
|
163
|
+
*
|
|
164
|
+
* @param params.spec The spec to complete.
|
|
165
|
+
* @returns A new spec with defaults applied.
|
|
166
|
+
* @throws {InvalidArgumentError} when `spec` is not an object.
|
|
167
|
+
*/
|
|
168
|
+
export const normalizeProductSpec = ({ spec }) => {
|
|
169
|
+
if (!isPlainObject(spec)) {
|
|
170
|
+
throw new InvalidArgumentError('"spec" must be an object.');
|
|
171
|
+
}
|
|
172
|
+
const basicData = isPlainObject(spec.basicData) ? spec.basicData : {};
|
|
173
|
+
const dataModel = isPlainObject(spec.dataModel) ? spec.dataModel : {};
|
|
174
|
+
const sensor = isPlainObject(spec.sensor) ? spec.sensor : {};
|
|
175
|
+
const testEnvironment = isPlainObject(basicData.testEnvironment)
|
|
176
|
+
? basicData.testEnvironment
|
|
177
|
+
: {};
|
|
178
|
+
const { languages } = basicData;
|
|
179
|
+
return {
|
|
180
|
+
...spec,
|
|
181
|
+
basicData: {
|
|
182
|
+
...basicData,
|
|
183
|
+
name: typeof basicData.name === 'string' ? basicData.name : '',
|
|
184
|
+
version: typeof basicData.version === 'string' && basicData.version !== ''
|
|
185
|
+
? basicData.version
|
|
186
|
+
: '0.0.0',
|
|
187
|
+
database: isPlainObject(basicData.database) ? basicData.database : {},
|
|
188
|
+
extra: isPlainObject(basicData.extra) ? basicData.extra : {},
|
|
189
|
+
testEnvironment: {
|
|
190
|
+
image: typeof testEnvironment.image === 'string' ? testEnvironment.image : '',
|
|
191
|
+
command: typeof testEnvironment.command === 'string' ? testEnvironment.command : ''
|
|
192
|
+
},
|
|
193
|
+
// An EMPTY array is kept. `saveProductVersion` uses `languages || [...]`
|
|
194
|
+
// and `[]` is truthy in JavaScript, so the monolith preserves it; the
|
|
195
|
+
// Mongoose default only fires when the path is `undefined`. A user who
|
|
196
|
+
// deselected every language must generate the same product here.
|
|
197
|
+
languages: Array.isArray(languages) ? [...languages] : [...DEFAULT_LANGUAGES],
|
|
198
|
+
SRID: typeof basicData.SRID === 'string' && basicData.SRID !== ''
|
|
199
|
+
? basicData.SRID
|
|
200
|
+
: DEFAULT_SRID
|
|
201
|
+
},
|
|
202
|
+
dataModel: {
|
|
203
|
+
...dataModel,
|
|
204
|
+
cells: Array.isArray(dataModel.cells) ? [...dataModel.cells] : []
|
|
205
|
+
},
|
|
206
|
+
features: Array.isArray(spec.features)
|
|
207
|
+
? [...spec.features]
|
|
208
|
+
: isPlainObject(spec.features)
|
|
209
|
+
? { ...spec.features }
|
|
210
|
+
: [],
|
|
211
|
+
statics: Array.isArray(spec.statics) ? [...spec.statics] : [],
|
|
212
|
+
sensor: {
|
|
213
|
+
...sensor,
|
|
214
|
+
dsl: typeof sensor.dsl === 'string' ? sensor.dsl : '',
|
|
215
|
+
parsed: sensor.parsed ?? null
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/product/spec.ts"],"names":[],"m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,GAAG,EAAE,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACrD,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;SAC9B;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Product spec validation and default filling.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/rest/validators/productValidators.js` (createProductValidator,\r\n * updateProductValidator) and `commonValidators.js` (`nameRule`, `versionRule`)\r\n * - `linea/server/src/model/entities/product.js` — the Mongoose schema defaults\r\n * - `linea/server/src/model/services/generatePipeline.js:saveProductVersion`\r\n * (~212-222) — the defaults applied right before returning a generated product\r\n *\r\n * The monolith validates at the HTTP edge with express-validator and fills\r\n * defaults twice: once through the Mongoose schema and once again in\r\n * `saveProductVersion`. Neither mechanism exists in linea-core, so both collapse\r\n * into these two functions.\r\n *\r\n * `linea-cli/src/core/specSchema.ts` duplicates the same rules with Zod today and\r\n * is meant to call this instead.\r\n */\r\nimport {\r\n DEFAULT_LANGUAGES,\r\n DEFAULT_SRID,\r\n NAME_PATTERN,\r\n VERSION_PATTERN\r\n} from '../constants.js'\r\nimport { InvalidArgumentError, InvalidProductSpecError } from '../errors.js'\r\nimport { isPlainObject } from '../internal/guards.js'\r\n\r\n/** `spec.basicData` — product identity and generation-wide settings. */\r\nexport interface ProductBasicData {\r\n name?: string\r\n version?: string\r\n languages?: string[]\r\n SRID?: string\r\n database?: Record<string, unknown>\r\n extra?: Record<string, unknown>\r\n testEnvironment?: { image?: string, command?: string }\r\n createdAt?: unknown\r\n [key: string]: unknown\r\n}\r\n\r\n/** A product spec as stored by the monolith and consumed by the engine. */\r\nexport interface ProductSpec {\r\n basicData?: ProductBasicData\r\n dataModel?: { cells?: unknown[], [key: string]: unknown }\r\n features?: string[] | Record<string, boolean>\r\n statics?: unknown[]\r\n sensor?: { dsl?: string, parsed?: unknown }\r\n /** Legacy feature-selection field. */\r\n selection?: string[]\r\n [key: string]: unknown\r\n}\r\n\r\n/** A single spec problem. */\r\nexport interface ProductSpecError {\r\n /** Dotted path of the offending field, e.g. `spec.basicData.name`. */\r\n readonly path: string\r\n /** Stable machine-readable discriminator. */\r\n readonly code: ProductSpecErrorCode\r\n /**\r\n * An i18n KEY, never a human-readable sentence. Always pass it through the\r\n * consumer's translation function; there is nothing sensible to render raw.\r\n *\r\n * Five keys are INHERITED verbatim from the monolith and already have\r\n * translations in `linea/client/src/i18n/{en,es,gl}`:\r\n * `spec_object_validation`, `basicData_object_validation`,\r\n * `basicData_name_validation`, `invalid_name_characters`,\r\n * `basicData_version_format`.\r\n *\r\n * Four keys are NEW and have NO translation yet, because the monolith enforced\r\n * these constraints through the Mongoose schema rather than express-validator,\r\n * so there was no key to copy: `basicData_languages_validation`,\r\n * `basicData_SRID_validation`, `spec_features_validation`,\r\n * `spec_statics_validation`. Until webui and linea-cli add them, vue-i18n will\r\n * render the key itself. Tracked in CHANGELOG.md.\r\n */\r\n readonly messageKey: string\r\n}\r\n\r\n/** Stable discriminators for spec problems. */\r\nexport type ProductSpecErrorCode =\r\n | 'SPEC_NOT_OBJECT'\r\n | 'BASIC_DATA_NOT_OBJECT'\r\n | 'NAME_REQUIRED'\r\n | 'NAME_INVALID_CHARACTERS'\r\n | 'VERSION_FORMAT'\r\n | 'LANGUAGES_NOT_STRING_ARRAY'\r\n | 'SRID_NOT_STRING'\r\n | 'FEATURES_INVALID_SHAPE'\r\n | 'STATICS_NOT_ARRAY'\r\n\r\n/** Result of validating a spec. */\r\nexport interface ProductSpecValidation {\r\n readonly valid: boolean\r\n readonly errors: ProductSpecError[]\r\n}\r\n\r\n/**\r\n * Validates a product spec **without throwing**.\r\n *\r\n * Reproduces `createProductValidator` / `updateProductValidator` with their exact\r\n * i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema\r\n * used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry\r\n * new keys with no translation yet — see `ProductSpecError.messageKey`.\r\n *\r\n * `lineId` is NOT validated here: it is a GitLab/persistence concern that lives\r\n * in linea-server (ADR-003), even though `createProductValidator` checks it.\r\n *\r\n * @param params.spec The spec to validate. Anything, including nullish.\r\n * @returns `valid` plus one entry per problem, in a stable order.\r\n */\r\nexport const validateProductSpec = ({ spec }: { spec: unknown }): ProductSpecValidation => {\r\n const errors: ProductSpecError[] = []\r\n\r\n if (!isPlainObject(spec)) {\r\n return {\r\n valid: false,\r\n errors: [{\r\n path: 'spec',\r\n code: 'SPEC_NOT_OBJECT',\r\n messageKey: 'error_messages.spec_object_validation'\r\n }]\r\n }\r\n }\r\n\r\n const basicData = spec.basicData\r\n if (!isPlainObject(basicData)) {\r\n return {\r\n valid: false,\r\n errors: [{\r\n path: 'spec.basicData',\r\n code: 'BASIC_DATA_NOT_OBJECT',\r\n messageKey: 'error_messages.basicData_object_validation'\r\n }]\r\n }\r\n }\r\n\r\n const name = basicData.name\r\n if (typeof name !== 'string' || name === '') {\r\n errors.push({\r\n path: 'spec.basicData.name',\r\n code: 'NAME_REQUIRED',\r\n messageKey: 'error_messages.basicData_name_validation'\r\n })\r\n } else if (!NAME_PATTERN.test(name)) {\r\n errors.push({\r\n path: 'spec.basicData.name',\r\n code: 'NAME_INVALID_CHARACTERS',\r\n messageKey: 'error_messages.invalid_name_characters'\r\n })\r\n }\r\n\r\n if (typeof basicData.version !== 'string' || !VERSION_PATTERN.test(basicData.version)) {\r\n errors.push({\r\n path: 'spec.basicData.version',\r\n code: 'VERSION_FORMAT',\r\n messageKey: 'error_messages.basicData_version_format'\r\n })\r\n }\r\n\r\n const { languages } = basicData\r\n if (\r\n languages !== undefined &&\r\n (!Array.isArray(languages) || languages.some((l) => typeof l !== 'string'))\r\n ) {\r\n errors.push({\r\n path: 'spec.basicData.languages',\r\n code: 'LANGUAGES_NOT_STRING_ARRAY',\r\n messageKey: 'error_messages.basicData_languages_validation'\r\n })\r\n }\r\n\r\n if (basicData.SRID !== undefined && typeof basicData.SRID !== 'string') {\r\n errors.push({\r\n path: 'spec.basicData.SRID',\r\n code: 'SRID_NOT_STRING',\r\n messageKey: 'error_messages.basicData_SRID_validation'\r\n })\r\n }\r\n\r\n const { features } = spec\r\n const featuresValid =\r\n features === undefined ||\r\n (Array.isArray(features) && features.every((f) => typeof f === 'string')) ||\r\n isPlainObject(features)\r\n if (!featuresValid) {\r\n errors.push({\r\n path: 'spec.features',\r\n code: 'FEATURES_INVALID_SHAPE',\r\n messageKey: 'error_messages.spec_features_validation'\r\n })\r\n }\r\n\r\n if (spec.statics !== undefined && !Array.isArray(spec.statics)) {\r\n errors.push({\r\n path: 'spec.statics',\r\n code: 'STATICS_NOT_ARRAY',\r\n messageKey: 'error_messages.spec_statics_validation'\r\n })\r\n }\r\n\r\n return { valid: errors.length === 0, errors }\r\n}\r\n\r\n/**\r\n * Validates a product spec and throws when it is not acceptable.\r\n *\r\n * The throwing counterpart of `validateProductSpec`, mirroring the\r\n * `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes\r\n * `InvalidProductSpecError` reachable: the monolith's equivalent is\r\n * express-validator short-circuiting the request with a 400 before\r\n * `ProductService.createProduct` ever runs, which has no direct analogue in a\r\n * library.\r\n *\r\n * The message lists every problem with its i18n key. Callers that need the\r\n * problems as DATA (to build an HTTP response body, say) should call\r\n * `validateProductSpec` instead — that is precisely what it is for, and it keeps\r\n * this error free of ad-hoc payload properties.\r\n *\r\n * @param params.spec The spec to validate.\r\n * @returns The spec, unchanged, when it is valid.\r\n * @throws {InvalidProductSpecError} listing every problem found.\r\n */\r\nexport const assertProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\r\n const { valid, errors } = validateProductSpec({ spec })\r\n if (!valid) {\r\n const summary = errors.map((error) => `${error.path}: ${error.messageKey}`).join('; ')\r\n throw new InvalidProductSpecError(`Invalid product spec: ${summary}`)\r\n }\r\n return spec\r\n}\r\n\r\n/**\r\n * Fills a product spec with the domain defaults.\r\n *\r\n * Union of the two places the monolith applies defaults:\r\n * - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,\r\n * `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`\r\n * `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,\r\n * `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.\r\n * - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies\r\n * `database`, `extra`, `languages` and `SRID` with `||` right before returning.\r\n *\r\n * `||` semantics are preserved for those four, which is subtler than it looks:\r\n * an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an\r\n * EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.\r\n *\r\n * PURE: returns a new object and never mutates the input. `basicData.createdAt`\r\n * is deliberately NOT filled — the schema defaults it to `Date.now`, which would\r\n * make this function non-deterministic. Timestamping is persistence metadata and\r\n * belongs to linea-server.\r\n *\r\n * @param params.spec The spec to complete.\r\n * @returns A new spec with defaults applied.\r\n * @throws {InvalidArgumentError} when `spec` is not an object.\r\n */\r\nexport const normalizeProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\r\n if (!isPlainObject(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n const basicData = isPlainObject(spec.basicData) ? spec.basicData : {}\r\n const dataModel = isPlainObject(spec.dataModel) ? spec.dataModel : {}\r\n const sensor = isPlainObject(spec.sensor) ? spec.sensor : {}\r\n const testEnvironment = isPlainObject(basicData.testEnvironment)\r\n ? basicData.testEnvironment\r\n : {}\r\n\r\n const { languages } = basicData\r\n\r\n return {\r\n ...spec,\r\n basicData: {\r\n ...basicData,\r\n name: typeof basicData.name === 'string' ? basicData.name : '',\r\n version: typeof basicData.version === 'string' && basicData.version !== ''\r\n ? basicData.version\r\n : '0.0.0',\r\n database: isPlainObject(basicData.database) ? basicData.database : {},\r\n extra: isPlainObject(basicData.extra) ? basicData.extra : {},\r\n testEnvironment: {\r\n image: typeof testEnvironment.image === 'string' ? testEnvironment.image : '',\r\n command: typeof testEnvironment.command === 'string' ? testEnvironment.command : ''\r\n },\r\n // An EMPTY array is kept. `saveProductVersion` uses `languages || [...]`\r\n // and `[]` is truthy in JavaScript, so the monolith preserves it; the\r\n // Mongoose default only fires when the path is `undefined`. A user who\r\n // deselected every language must generate the same product here.\r\n languages: Array.isArray(languages) ? [...languages] : [...DEFAULT_LANGUAGES],\r\n SRID: typeof basicData.SRID === 'string' && basicData.SRID !== ''\r\n ? basicData.SRID\r\n : DEFAULT_SRID\r\n },\r\n dataModel: {\r\n ...dataModel,\r\n cells: Array.isArray(dataModel.cells) ? [...dataModel.cells] : []\r\n },\r\n features: Array.isArray(spec.features)\r\n ? [...spec.features]\r\n : isPlainObject(spec.features)\r\n ? { ...spec.features }\r\n : [],\r\n statics: Array.isArray(spec.statics) ? [...spec.statics] : [],\r\n sensor: {\r\n ...sensor,\r\n dsl: typeof sensor.dsl === 'string' ? sensor.dsl : '',\r\n parsed: sensor.parsed ?? null\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bumps one component of an `x.y.z` version, zeroing everything to its right.
|
|
3
|
+
*
|
|
4
|
+
* Verbatim algorithm of the monolith: the component at `index` is incremented
|
|
5
|
+
* and every component after it is reset to 0.
|
|
6
|
+
*
|
|
7
|
+
* incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'
|
|
8
|
+
* incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'
|
|
9
|
+
* incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'
|
|
10
|
+
*
|
|
11
|
+
* The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and
|
|
12
|
+
* on a conversion, and index 2 on a product generation.
|
|
13
|
+
*
|
|
14
|
+
* HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no
|
|
15
|
+
* validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.
|
|
16
|
+
* Here a version that does not match `VERSION_PATTERN` is rejected.
|
|
17
|
+
*
|
|
18
|
+
* @param params.version Current version, `x.y.z`.
|
|
19
|
+
* @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.
|
|
20
|
+
* @returns The bumped version.
|
|
21
|
+
* @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not
|
|
22
|
+
* an integer in `[0, 2]`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const incrementVersion: ({ version, index }: {
|
|
25
|
+
version: string;
|
|
26
|
+
index: number;
|
|
27
|
+
}) => string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Product version arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/services/utils.js:incrementVersion` (~152-163).
|
|
5
|
+
*/
|
|
6
|
+
import { VERSION_PATTERN } from '../constants.js';
|
|
7
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
8
|
+
/**
|
|
9
|
+
* Bumps one component of an `x.y.z` version, zeroing everything to its right.
|
|
10
|
+
*
|
|
11
|
+
* Verbatim algorithm of the monolith: the component at `index` is incremented
|
|
12
|
+
* and every component after it is reset to 0.
|
|
13
|
+
*
|
|
14
|
+
* incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'
|
|
15
|
+
* incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'
|
|
16
|
+
* incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'
|
|
17
|
+
*
|
|
18
|
+
* The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and
|
|
19
|
+
* on a conversion, and index 2 on a product generation.
|
|
20
|
+
*
|
|
21
|
+
* HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no
|
|
22
|
+
* validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.
|
|
23
|
+
* Here a version that does not match `VERSION_PATTERN` is rejected.
|
|
24
|
+
*
|
|
25
|
+
* @param params.version Current version, `x.y.z`.
|
|
26
|
+
* @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.
|
|
27
|
+
* @returns The bumped version.
|
|
28
|
+
* @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not
|
|
29
|
+
* an integer in `[0, 2]`.
|
|
30
|
+
*/
|
|
31
|
+
export const incrementVersion = ({ version, index }) => {
|
|
32
|
+
if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {
|
|
33
|
+
throw new InvalidArgumentError(`"version" must match x.y.z, got ${JSON.stringify(version)}.`);
|
|
34
|
+
}
|
|
35
|
+
if (!Number.isInteger(index) || index < 0 || index > 2) {
|
|
36
|
+
throw new InvalidArgumentError(`"index" must be an integer in [0, 2], got ${String(index)}.`);
|
|
37
|
+
}
|
|
38
|
+
const parts = version.split('.').map(Number);
|
|
39
|
+
return parts
|
|
40
|
+
.map((part, i) => {
|
|
41
|
+
if (i === index)
|
|
42
|
+
return part + 1;
|
|
43
|
+
if (i > index)
|
|
44
|
+
return 0;
|
|
45
|
+
return part;
|
|
46
|
+
})
|
|
47
|
+
.join('.');
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/product/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,OAAO,EACP,KAAK,EAIN,EAAU,EAAE;IACX,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,oBAAoB,CAC5B,mCAAmC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAC9D,CAAA;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,oBAAoB,CAAC,6CAA6C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/F,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC5C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QACf,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,IAAI,GAAG,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,KAAK;YAAE,OAAO,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC,CAAA","sourcesContent":["/**\r\n * Product version arithmetic.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:incrementVersion` (~152-163).\r\n */\r\nimport { VERSION_PATTERN } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * Bumps one component of an `x.y.z` version, zeroing everything to its right.\r\n *\r\n * Verbatim algorithm of the monolith: the component at `index` is incremented\r\n * and every component after it is reset to 0.\r\n *\r\n * incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'\r\n * incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'\r\n * incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'\r\n *\r\n * The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and\r\n * on a conversion, and index 2 on a product generation.\r\n *\r\n * HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no\r\n * validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.\r\n * Here a version that does not match `VERSION_PATTERN` is rejected.\r\n *\r\n * @param params.version Current version, `x.y.z`.\r\n * @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.\r\n * @returns The bumped version.\r\n * @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not\r\n * an integer in `[0, 2]`.\r\n */\r\nexport const incrementVersion = ({\r\n version,\r\n index\r\n}: {\r\n version: string\r\n index: number\r\n}): string => {\r\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\r\n throw new InvalidArgumentError(\r\n `\"version\" must match x.y.z, got ${JSON.stringify(version)}.`\r\n )\r\n }\r\n if (!Number.isInteger(index) || index < 0 || index > 2) {\r\n throw new InvalidArgumentError(`\"index\" must be an integer in [0, 2], got ${String(index)}.`)\r\n }\r\n\r\n const parts = version.split('.').map(Number)\r\n return parts\r\n .map((part, i) => {\r\n if (i === index) return part + 1\r\n if (i > index) return 0\r\n return part\r\n })\r\n .join('.')\r\n}\r\n"]}
|