@ng-org/shex-orm 0.1.2-alpha.2 → 0.1.2-alpha.3

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.
@@ -330,7 +330,7 @@ export declare const ShexJSchemaTransformerCompact: import("@ldo/type-traverser"
330
330
  return: Predicate;
331
331
  };
332
332
  NodeConstraint: {
333
- return: DataType;
333
+ return: DataType | DataType[];
334
334
  };
335
335
  ShapeOr: {
336
336
  return: DataType[];
@@ -1 +1 @@
1
- {"version":3,"file":"ShexJSchemaTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJSchemaTransformer.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AA0DjE,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAE1B;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE;eAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;WACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;YAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;sBACP;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE;oBACvB;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE;aAC3B;QAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;KAAE;cACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;cACjB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;mBACZ;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;QAiNtC,CAAC"}
1
+ {"version":3,"file":"ShexJSchemaTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJSchemaTransformer.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAyDjE,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAE1B;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE;eAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;WACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;YAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;sBACP;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE;oBACvB;QAAE,MAAM,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAA;KAAE;aACxC;QAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;KAAE;cACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;cACjB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;mBACZ;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;QA+OtC,CAAC"}
@@ -140,26 +140,17 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
140
140
  };
141
141
  }
142
142
  else if (Array.isArray(transformedChildren.valueExpr)) {
143
+ // DataType[] from ShapeOr or NodeConstraint with mixed types.
143
144
  return {
144
145
  dataTypes: transformedChildren.valueExpr, // DataType[]
145
146
  ...commonProperties,
146
147
  };
147
148
  }
148
149
  else {
149
- // type or literal
150
+ // Single DataType from NodeConstraint.
150
151
  const nodeConstraint = transformedChildren.valueExpr;
151
152
  return {
152
- dataTypes: !Array.isArray(nodeConstraint.literals)
153
- ? [
154
- {
155
- valType: nodeConstraint.valType,
156
- literals: nodeConstraint.literals,
157
- },
158
- ]
159
- : nodeConstraint.literals.map((lit) => ({
160
- valType: nodeConstraint.valType,
161
- literals: [lit],
162
- })),
153
+ dataTypes: [nodeConstraint],
163
154
  ...commonProperties,
164
155
  };
165
156
  }
@@ -177,36 +168,70 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
177
168
  return { valType: "iri" };
178
169
  }
179
170
  if (nodeConstraint.values) {
180
- return {
181
- valType: "literal",
182
- literals: nodeConstraint.values.map(
183
- // TODO: We do not convert them to number or boolean or lang tag.
184
- // And we don't have an annotation of the literal's type.
185
- (valueRecord) => {
186
- // If valueRecord is a string (IRIREF), return it directly
187
- if (typeof valueRecord === "string") {
188
- return valueRecord;
189
- }
190
- // Handle ObjectLiteral (has .value property)
191
- if ("value" in valueRecord) {
192
- return valueRecord.value;
171
+ // In ShEx, [val1 val2 val3] means "one of these values" (OR semantics).
172
+ // Each literal value becomes a separate DataType entry.
173
+ const dataTypes = nodeConstraint.values.map((valueRecord) => {
174
+ // If valueRecord is an IRIREF...
175
+ if (typeof valueRecord === "string") {
176
+ return {
177
+ valType: "iri",
178
+ literals: [valueRecord],
179
+ };
180
+ }
181
+ // Handle ObjectLiteral (has .value property).
182
+ if ("value" in valueRecord) {
183
+ const val = valueRecord.value;
184
+ // Determine type from datatype if available.
185
+ if ("type" in valueRecord && valueRecord.type) {
186
+ return {
187
+ valType: rdfDataTypeToBasic(valueRecord.type),
188
+ literals: [val],
189
+ };
193
190
  }
194
- // Handle other types with .id property (if any)
195
- if ("id" in valueRecord) {
196
- return valueRecord.id;
191
+ if (typeof val === "number") {
192
+ return {
193
+ valType: "number",
194
+ literals: [val],
195
+ };
197
196
  }
198
- // Handle Language type (has .languageTag)
199
- if ("languageTag" in valueRecord) {
200
- return valueRecord.languageTag;
197
+ if (typeof val === "boolean") {
198
+ return {
199
+ valType: "boolean",
200
+ literals: [val],
201
+ };
201
202
  }
202
- // Handle stem-based types (IriStem, LiteralStem, LanguageStem)
203
- if ("stem" in valueRecord) {
204
- return valueRecord.stem;
205
- }
206
- // Fallback - should not happen in well-formed ShEx
207
- return undefined;
208
- }),
209
- };
203
+ return {
204
+ valType: "string",
205
+ literals: [val],
206
+ };
207
+ }
208
+ // Handle other types with .id property (if any).
209
+ if ("id" in valueRecord) {
210
+ return {
211
+ valType: "iri",
212
+ literals: [valueRecord.id],
213
+ };
214
+ }
215
+ // Handle language-tagged strings.
216
+ if ("languageTag" in valueRecord) {
217
+ return {
218
+ valType: "string",
219
+ literals: [valueRecord.languageTag],
220
+ };
221
+ }
222
+ // Handle stem-based types (IriStem, LiteralStem, LanguageStem).
223
+ if ("stem" in valueRecord) {
224
+ return {
225
+ valType: "string",
226
+ literals: [valueRecord.stem],
227
+ };
228
+ }
229
+ // Fallback - should not happen in well-formed ShEx
230
+ return {
231
+ valType: "string",
232
+ };
233
+ });
234
+ return dataTypes;
210
235
  }
211
236
  // Maybe we should throw instead...
212
237
  throw {
@@ -219,8 +244,11 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
219
244
  ShapeOr: {
220
245
  transformer: async (shapeOr, getTransformedChildren) => {
221
246
  const { shapeExprs } = await getTransformedChildren();
222
- // Either a shape IRI, a nested shape or a node CompactSchemaValue (node constraint).
223
- return (Array.isArray(shapeExprs) ? shapeExprs : [shapeExprs]);
247
+ // Each shapeExpr can be a shape IRI (string), a nested Shape, a DataType,
248
+ // or a DataType[] (from NodeConstraint with multiple types).
249
+ // We need to flatten arrays to get a single DataType[].
250
+ const exprs = Array.isArray(shapeExprs) ? shapeExprs : [shapeExprs];
251
+ return exprs.flatMap((expr) => Array.isArray(expr) ? expr : [expr]);
224
252
  },
225
253
  },
226
254
  // Transformer from ShapeAnd
package/dist/types.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * TODO: Short documentation on schema generation
3
+ */
1
4
  export interface ShapeType<T extends BaseType> {
2
5
  schema: Schema;
3
6
  shape: string;
@@ -13,12 +16,12 @@ export interface Shape {
13
16
  predicates: Predicate[];
14
17
  }
15
18
  export type DataType = {
16
- /** The required literal value(s), if type is `literal`. Others are allowed, if `extra` is true. */
19
+ /** The required literal value(s). Additional values are allowed, if `extra` is true. */
17
20
  literals?: number[] | string[] | boolean;
18
21
  /** If `valType` is `"shape"`, the nested shape or its reference. Use reference for serialization. */
19
22
  shape?: string | Shape;
20
23
  /** The type of object value for a triple constraint. */
21
- valType: "number" | "string" | "boolean" | "iri" | "literal" | "shape";
24
+ valType: "number" | "string" | "boolean" | "iri" | "shape";
22
25
  };
23
26
  export interface Predicate {
24
27
  /** Allowed type of object. If more than one is present, either of them is allowed. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,QAAQ;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAS,SAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACjD,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,MAAM,GAAG;IACjB,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,KAAK;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,SAA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,CAAC;IACzC,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,wDAAwD;IACxD,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;CAC9D,CAAC;AAEF,MAAM,WAAW,SAAS;IACtB,sFAAsF;IACtF,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "@ng-org/shex-orm",
3
- "version": "0.1.2-alpha.2",
3
+ "version": "0.1.2-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
6
+ "main": "src/index.ts",
7
7
  "bin": {
8
- "rdf-orm": "./dist/cli.js"
8
+ "rdf-orm": "./src/cli.ts"
9
+ },
10
+ "scripts": {
11
+ "build": "pnpm run build:ts",
12
+ "build:ts": "rm -rf dist && tsc && pnpm run update-permission && pnpm copy-templates",
13
+ "copy-templates": "mkdir -p dist && rsync -qav --include=\"*/\" --include=\"*.ejs\" --exclude=\"*\" src/ dist/",
14
+ "update-permission": "chmod +x ./dist/cli.js",
15
+ "test": "vitest run",
16
+ "prepublishOnly": "pnpm run build",
17
+ "lint": "eslint src/** --fix --no-error-on-unmatched-pattern",
18
+ "test:init": "rm -rf ./example-init && cp -R ./example-init-placeholder ./example-init && cd ./example-init && ../dist/index.js init",
19
+ "test:create": "rm -rf ./example-create && ./dist/index.js create ./example-create"
9
20
  },
10
21
  "authors": [
11
22
  "Laurin Weger",
@@ -45,17 +56,11 @@
45
56
  "dist"
46
57
  ],
47
58
  "publishConfig": {
48
- "access": "public"
49
- },
50
- "scripts": {
51
- "build": "pnpm run build:ts",
52
- "build:ts": "rm -rf dist && tsc && pnpm run update-permission && pnpm copy-templates",
53
- "copy-templates": "mkdir -p dist && rsync -qav --include=\"*/\" --include=\"*.ejs\" --exclude=\"*\" src/ dist/",
54
- "update-permission": "chmod +x ./dist/cli.js",
55
- "test": "vitest run",
56
- "lint": "eslint src/** --fix --no-error-on-unmatched-pattern",
57
- "test:init": "rm -rf ./example-init && cp -R ./example-init-placeholder ./example-init && cd ./example-init && ../dist/index.js init",
58
- "test:create": "rm -rf ./example-create && ./dist/index.js create ./example-create"
59
- },
60
- "types": "./dist/index.d.ts"
61
- }
59
+ "bin": {
60
+ "rdf-orm": "./dist/cli.js"
61
+ },
62
+ "access": "public",
63
+ "main": "./dist/index.js",
64
+ "types": "./dist/index.d.ts"
65
+ }
66
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from "commander";
4
+ import { build } from "./build.ts";
5
+
6
+ program
7
+ .name("NG-ORM")
8
+ .description("CLI to some JavaScript string utilities")
9
+ .version("0.1.0");
10
+
11
+ program
12
+ .command("build")
13
+ .description("Build contents of a shex folder into Shape Types")
14
+ .option("-i, --input <inputPath>", "Provide the input path", "./.shapes")
15
+ .option("-o, --output <outputPath>", "Provide the output path", "./.orm")
16
+ .option(
17
+ "-b, --baseIRI <baseIri>",
18
+ "The base IRI for anonymous shapes",
19
+ "https://nextgraph.org/shapes#"
20
+ )
21
+ .action(build);
22
+
23
+ program.parse();
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./types.ts";