@odata-effect/odata-effect-generator 0.2.0 → 0.3.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.
- package/README.md +17 -8
- package/dist/cjs/Cli.js +2 -2
- package/dist/cjs/Cli.js.map +1 -1
- package/dist/cjs/generator/Generator.js +5 -13
- package/dist/cjs/generator/Generator.js.map +1 -1
- package/dist/cjs/generator/IndexGenerator.js +14 -11
- package/dist/cjs/generator/IndexGenerator.js.map +1 -1
- package/dist/cjs/generator/ModelsGenerator.js +2 -5
- package/dist/cjs/generator/ModelsGenerator.js.map +1 -1
- package/dist/cjs/generator/NamingHelper.js.map +1 -1
- package/dist/cjs/generator/NavigationGenerator.js +42 -13
- package/dist/cjs/generator/NavigationGenerator.js.map +1 -1
- package/dist/cjs/generator/OperationsGenerator.js +2 -2
- package/dist/cjs/generator/OperationsGenerator.js.map +1 -1
- package/dist/cjs/generator/ServiceFnGenerator.js +102 -224
- package/dist/cjs/generator/ServiceFnGenerator.js.map +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/dts/Cli.d.ts.map +1 -1
- package/dist/dts/generator/Generator.d.ts.map +1 -1
- package/dist/dts/generator/IndexGenerator.d.ts.map +1 -1
- package/dist/dts/generator/NamingHelper.d.ts.map +1 -1
- package/dist/dts/generator/NavigationGenerator.d.ts.map +1 -1
- package/dist/dts/generator/ServiceFnGenerator.d.ts +10 -11
- package/dist/dts/generator/ServiceFnGenerator.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -4
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/Cli.js +2 -2
- package/dist/esm/Cli.js.map +1 -1
- package/dist/esm/generator/Generator.js +5 -13
- package/dist/esm/generator/Generator.js.map +1 -1
- package/dist/esm/generator/IndexGenerator.js +14 -11
- package/dist/esm/generator/IndexGenerator.js.map +1 -1
- package/dist/esm/generator/ModelsGenerator.js +2 -5
- package/dist/esm/generator/ModelsGenerator.js.map +1 -1
- package/dist/esm/generator/NamingHelper.js.map +1 -1
- package/dist/esm/generator/NavigationGenerator.js +42 -13
- package/dist/esm/generator/NavigationGenerator.js.map +1 -1
- package/dist/esm/generator/OperationsGenerator.js +2 -2
- package/dist/esm/generator/OperationsGenerator.js.map +1 -1
- package/dist/esm/generator/ServiceFnGenerator.js +102 -224
- package/dist/esm/generator/ServiceFnGenerator.js.map +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -9
- package/src/Cli.ts +8 -1
- package/src/generator/Generator.ts +8 -17
- package/src/generator/IndexGenerator.ts +14 -12
- package/src/generator/ModelsGenerator.ts +2 -5
- package/src/generator/NamingHelper.ts +5 -3
- package/src/generator/NavigationGenerator.ts +55 -26
- package/src/generator/OperationsGenerator.ts +40 -14
- package/src/generator/ServiceFnGenerator.ts +117 -265
- package/src/index.ts +4 -4
- package/dist/cjs/generator/ServiceFnPromiseGenerator.js +0 -183
- package/dist/cjs/generator/ServiceFnPromiseGenerator.js.map +0 -1
- package/dist/dts/generator/ServiceFnPromiseGenerator.d.ts +0 -40
- package/dist/dts/generator/ServiceFnPromiseGenerator.d.ts.map +0 -1
- package/dist/esm/generator/ServiceFnPromiseGenerator.js +0 -175
- package/dist/esm/generator/ServiceFnPromiseGenerator.js.map +0 -1
- package/generator/ServiceFnPromiseGenerator/package.json +0 -6
- package/src/generator/ServiceFnPromiseGenerator.ts +0 -243
|
@@ -21,15 +21,9 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @since 1.0.0
|
|
23
23
|
*/
|
|
24
|
-
import type {
|
|
25
|
-
DataModel,
|
|
26
|
-
EntityTypeModel
|
|
27
|
-
} from "../model/DataModel.js"
|
|
24
|
+
import type { DataModel, EntityTypeModel } from "../model/DataModel.js"
|
|
28
25
|
import type { ODataVersion } from "../parser/EdmxSchema.js"
|
|
29
|
-
import {
|
|
30
|
-
getClassName,
|
|
31
|
-
toCamelCase
|
|
32
|
-
} from "./NamingHelper.js"
|
|
26
|
+
import { getClassName, toCamelCase } from "./NamingHelper.js"
|
|
33
27
|
|
|
34
28
|
/**
|
|
35
29
|
* Version-specific configuration.
|
|
@@ -42,18 +36,17 @@ interface VersionConfig {
|
|
|
42
36
|
|
|
43
37
|
const V2_CONFIG: VersionConfig = {
|
|
44
38
|
odataNamespace: "OData",
|
|
45
|
-
clientModule: "
|
|
39
|
+
clientModule: "OData",
|
|
46
40
|
queryOptionsType: "ODataQueryOptions"
|
|
47
41
|
}
|
|
48
42
|
|
|
49
43
|
const V4_CONFIG: VersionConfig = {
|
|
50
44
|
odataNamespace: "ODataV4",
|
|
51
|
-
clientModule: "
|
|
45
|
+
clientModule: "ODataV4",
|
|
52
46
|
queryOptionsType: "ODataV4QueryOptions"
|
|
53
47
|
}
|
|
54
48
|
|
|
55
|
-
const getVersionConfig = (version: ODataVersion): VersionConfig =>
|
|
56
|
-
version === "V4" ? V4_CONFIG : V2_CONFIG
|
|
49
|
+
const getVersionConfig = (version: ODataVersion): VersionConfig => version === "V4" ? V4_CONFIG : V2_CONFIG
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
52
|
* Get the path builders module name.
|
|
@@ -163,7 +156,10 @@ const getDerivedTypes = (
|
|
|
163
156
|
if (entityType.baseType === baseTypeFqName) {
|
|
164
157
|
derived.push(entityType)
|
|
165
158
|
// Recursively get further derived types
|
|
166
|
-
|
|
159
|
+
const furtherDerived = getDerivedTypes(entityType.fqName, dataModel)
|
|
160
|
+
for (const d of furtherDerived) {
|
|
161
|
+
derived.push(d)
|
|
162
|
+
}
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
165
|
|
|
@@ -226,9 +222,9 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
226
222
|
lines.push(``)
|
|
227
223
|
|
|
228
224
|
// Imports
|
|
229
|
-
lines.push(`import
|
|
230
|
-
lines.push(`import
|
|
231
|
-
lines.push(`import type
|
|
225
|
+
lines.push(`import { ${versionConfig.odataNamespace} } from "@odata-effect/odata-effect"`)
|
|
226
|
+
lines.push(`import { toPromise } from "@odata-effect/odata-effect-promise"`)
|
|
227
|
+
lines.push(`import type { Effect, Schema } from "effect"`)
|
|
232
228
|
lines.push(``)
|
|
233
229
|
|
|
234
230
|
// Import model types with Model suffix to avoid collision with entity set names
|
|
@@ -276,7 +272,9 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
276
272
|
lines.push(` * @since 1.0.0`)
|
|
277
273
|
lines.push(` * @category entity-sets`)
|
|
278
274
|
lines.push(` */`)
|
|
279
|
-
lines.push(
|
|
275
|
+
lines.push(
|
|
276
|
+
`export const ${entitySet.name}: Path<${entityType.name}Model, true> = "${entitySet.name}" as Path<${entityType.name}Model, true>`
|
|
277
|
+
)
|
|
280
278
|
lines.push(``)
|
|
281
279
|
}
|
|
282
280
|
}
|
|
@@ -331,7 +329,9 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
331
329
|
lines.push(` * @since 1.0.0`)
|
|
332
330
|
lines.push(` * @category navigation`)
|
|
333
331
|
lines.push(` */`)
|
|
334
|
-
lines.push(
|
|
332
|
+
lines.push(
|
|
333
|
+
`export const ${fnName} = (base: Path<${sourceEntity}Model, false>): Path<${targetType}Model, ${prop.isCollection}> =>`
|
|
334
|
+
)
|
|
335
335
|
lines.push(` \`\${base}/${prop.odataName}\` as Path<${targetType}Model, ${prop.isCollection}>`)
|
|
336
336
|
lines.push(``)
|
|
337
337
|
}
|
|
@@ -344,16 +344,18 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
344
344
|
lines.push(`// Type Casting (for entity inheritance)`)
|
|
345
345
|
lines.push(`// ============================================================================`)
|
|
346
346
|
lines.push(``)
|
|
347
|
-
|
|
347
|
+
for (const castFunction of castFunctions) {
|
|
348
|
+
lines.push(castFunction)
|
|
349
|
+
}
|
|
348
350
|
}
|
|
349
351
|
|
|
350
|
-
// Terminal operations
|
|
352
|
+
// Terminal operations (Effect-based)
|
|
351
353
|
lines.push(`// ============================================================================`)
|
|
352
|
-
lines.push(`// Terminal Operations`)
|
|
354
|
+
lines.push(`// Terminal Operations (Effect-based)`)
|
|
353
355
|
lines.push(`// ============================================================================`)
|
|
354
356
|
lines.push(``)
|
|
355
357
|
lines.push(`/**`)
|
|
356
|
-
lines.push(` * Fetch a collection of entities at the given path.`)
|
|
358
|
+
lines.push(` * Fetch a collection of entities at the given path (Effect-based).`)
|
|
357
359
|
lines.push(` *`)
|
|
358
360
|
lines.push(` * @example`)
|
|
359
361
|
lines.push(` * \`\`\`typescript`)
|
|
@@ -364,11 +366,11 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
364
366
|
lines.push(` * @category operations`)
|
|
365
367
|
lines.push(` */`)
|
|
366
368
|
lines.push(`export const fetchCollection = <T, I>(schema: Schema.Schema<T, I>) =>`)
|
|
367
|
-
lines.push(` (path: Path<T, true>, options?: ${versionConfig.queryOptionsType}) =>`)
|
|
369
|
+
lines.push(` (path: Path<T, true>, options?: ${versionConfig.clientModule}.${versionConfig.queryOptionsType}) =>`)
|
|
368
370
|
lines.push(` ${versionConfig.odataNamespace}.getCollection(path, schema, options)`)
|
|
369
371
|
lines.push(``)
|
|
370
372
|
lines.push(`/**`)
|
|
371
|
-
lines.push(` * Fetch a single entity at the given path.`)
|
|
373
|
+
lines.push(` * Fetch a single entity at the given path (Effect-based).`)
|
|
372
374
|
lines.push(` *`)
|
|
373
375
|
lines.push(` * @example`)
|
|
374
376
|
lines.push(` * \`\`\`typescript`)
|
|
@@ -379,10 +381,35 @@ const generatePathBuildersFile = (dataModel: DataModel): string => {
|
|
|
379
381
|
lines.push(` * @category operations`)
|
|
380
382
|
lines.push(` */`)
|
|
381
383
|
lines.push(`export const fetchOne = <T, I>(schema: Schema.Schema<T, I>) =>`)
|
|
382
|
-
lines.push(` (path: Path<T, false>, options?: ${versionConfig.queryOptionsType}) =>`)
|
|
384
|
+
lines.push(` (path: Path<T, false>, options?: ${versionConfig.clientModule}.${versionConfig.queryOptionsType}) =>`)
|
|
383
385
|
lines.push(` ${versionConfig.odataNamespace}.get(path, schema, options)`)
|
|
384
386
|
lines.push(``)
|
|
385
387
|
|
|
388
|
+
// Promise conversion (re-export from odata-effect-promise)
|
|
389
|
+
lines.push(`// ============================================================================`)
|
|
390
|
+
lines.push(`// Promise Conversion`)
|
|
391
|
+
lines.push(`// ============================================================================`)
|
|
392
|
+
lines.push(``)
|
|
393
|
+
lines.push(`/**`)
|
|
394
|
+
lines.push(` * Convert an Effect to a Promise. Use at the end of a pipe chain.`)
|
|
395
|
+
lines.push(` *`)
|
|
396
|
+
lines.push(` * @example`)
|
|
397
|
+
lines.push(` * \`\`\`typescript`)
|
|
398
|
+
lines.push(` * const myTrips = await pipe(`)
|
|
399
|
+
lines.push(` * People,`)
|
|
400
|
+
lines.push(` * byKey("russell"),`)
|
|
401
|
+
lines.push(` * trips,`)
|
|
402
|
+
lines.push(` * fetchCollection(Trip),`)
|
|
403
|
+
lines.push(` * toPromise(runtime)`)
|
|
404
|
+
lines.push(` * )`)
|
|
405
|
+
lines.push(` * \`\`\``)
|
|
406
|
+
lines.push(` *`)
|
|
407
|
+
lines.push(` * @since 1.0.0`)
|
|
408
|
+
lines.push(` * @category operations`)
|
|
409
|
+
lines.push(` */`)
|
|
410
|
+
lines.push(`export { toPromise }`)
|
|
411
|
+
lines.push(``)
|
|
412
|
+
|
|
386
413
|
return lines.join("\n")
|
|
387
414
|
}
|
|
388
415
|
|
|
@@ -409,7 +436,9 @@ const generateTypeCastFunctions = (dataModel: DataModel): Array<string> => {
|
|
|
409
436
|
lines.push(` * @since 1.0.0`)
|
|
410
437
|
lines.push(` * @category casting`)
|
|
411
438
|
lines.push(` */`)
|
|
412
|
-
lines.push(
|
|
439
|
+
lines.push(
|
|
440
|
+
`export const ${fnName} = (base: Path<${entityType.name}Model, true>): Path<${derived.name}Model, true> =>`
|
|
441
|
+
)
|
|
413
442
|
lines.push(` \`\${base}/${castPath}\` as Path<${derived.name}Model, true>`)
|
|
414
443
|
lines.push(``)
|
|
415
444
|
}
|
|
@@ -125,7 +125,7 @@ const returnsModelType = (operation: OperationModel, dataModel: DataModel): bool
|
|
|
125
125
|
const getReturnTypeName = (operation: OperationModel): string => {
|
|
126
126
|
if (!operation.returnType) return "void"
|
|
127
127
|
|
|
128
|
-
const {
|
|
128
|
+
const { isCollection, typeMapping } = operation.returnType
|
|
129
129
|
const baseType = typeMapping.tsType
|
|
130
130
|
|
|
131
131
|
return isCollection ? `ReadonlyArray<${baseType}>` : baseType
|
|
@@ -364,19 +364,29 @@ const generateV2FunctionImport = (
|
|
|
364
364
|
|
|
365
365
|
// Determine the execute function to use
|
|
366
366
|
if (!operation.returnType) {
|
|
367
|
-
lines.push(
|
|
367
|
+
lines.push(
|
|
368
|
+
` return yield* ODataOps.executeFunctionImportVoid(client, config, "${operation.odataName}", ${paramsArg})`
|
|
369
|
+
)
|
|
368
370
|
} else if (operation.returnType.isCollection) {
|
|
369
371
|
if (returnsModel) {
|
|
370
|
-
lines.push(
|
|
372
|
+
lines.push(
|
|
373
|
+
` return yield* ODataOps.executeFunctionImportCollection(client, config, "${operation.odataName}", ${operation.returnType.typeMapping.tsType}, ${paramsArg})`
|
|
374
|
+
)
|
|
371
375
|
} else {
|
|
372
|
-
lines.push(
|
|
376
|
+
lines.push(
|
|
377
|
+
` return yield* ODataOps.executeFunctionImportCollection(client, config, "${operation.odataName}", ${operation.returnType.typeMapping.effectSchema}, ${paramsArg})`
|
|
378
|
+
)
|
|
373
379
|
}
|
|
374
380
|
} else if (returnsModel) {
|
|
375
|
-
lines.push(
|
|
381
|
+
lines.push(
|
|
382
|
+
` return yield* ODataOps.executeFunctionImportEntity(client, config, "${operation.odataName}", ${operation.returnType.typeMapping.tsType}, ${paramsArg})`
|
|
383
|
+
)
|
|
376
384
|
} else {
|
|
377
385
|
// Primitive return
|
|
378
386
|
const propertyName = operation.odataName
|
|
379
|
-
lines.push(
|
|
387
|
+
lines.push(
|
|
388
|
+
` return yield* ODataOps.executeFunctionImportPrimitive(client, config, "${operation.odataName}", "${propertyName}", ${operation.returnType.typeMapping.effectSchema}, ${paramsArg})`
|
|
389
|
+
)
|
|
380
390
|
}
|
|
381
391
|
|
|
382
392
|
lines.push(` })`)
|
|
@@ -444,15 +454,23 @@ const generateV4Operation = (
|
|
|
444
454
|
lines.push(` return yield* ODataOps.executeV4FunctionVoid(client, config, url)`)
|
|
445
455
|
} else if (operation.returnType.isCollection) {
|
|
446
456
|
if (returnsModel) {
|
|
447
|
-
lines.push(
|
|
457
|
+
lines.push(
|
|
458
|
+
` return yield* ODataOps.executeV4FunctionCollection(client, config, url, ${operation.returnType.typeMapping.tsType})`
|
|
459
|
+
)
|
|
448
460
|
} else {
|
|
449
|
-
lines.push(
|
|
461
|
+
lines.push(
|
|
462
|
+
` return yield* ODataOps.executeV4FunctionCollection(client, config, url, ${operation.returnType.typeMapping.effectSchema})`
|
|
463
|
+
)
|
|
450
464
|
}
|
|
451
465
|
} else if (returnsModel) {
|
|
452
|
-
lines.push(
|
|
466
|
+
lines.push(
|
|
467
|
+
` return yield* ODataOps.executeV4FunctionEntity(client, config, url, ${operation.returnType.typeMapping.tsType})`
|
|
468
|
+
)
|
|
453
469
|
} else {
|
|
454
470
|
// Primitive return
|
|
455
|
-
lines.push(
|
|
471
|
+
lines.push(
|
|
472
|
+
` return yield* ODataOps.executeV4FunctionPrimitive(client, config, url, ${operation.returnType.typeMapping.effectSchema})`
|
|
473
|
+
)
|
|
456
474
|
}
|
|
457
475
|
} else {
|
|
458
476
|
// V4 Actions use POST with body
|
|
@@ -465,15 +483,23 @@ const generateV4Operation = (
|
|
|
465
483
|
lines.push(` return yield* ODataOps.executeV4ActionVoid(client, config, url, ${bodyArg})`)
|
|
466
484
|
} else if (operation.returnType.isCollection) {
|
|
467
485
|
if (returnsModel) {
|
|
468
|
-
lines.push(
|
|
486
|
+
lines.push(
|
|
487
|
+
` return yield* ODataOps.executeV4ActionCollection(client, config, url, ${operation.returnType.typeMapping.tsType}, ${bodyArg})`
|
|
488
|
+
)
|
|
469
489
|
} else {
|
|
470
|
-
lines.push(
|
|
490
|
+
lines.push(
|
|
491
|
+
` return yield* ODataOps.executeV4ActionCollection(client, config, url, ${operation.returnType.typeMapping.effectSchema}, ${bodyArg})`
|
|
492
|
+
)
|
|
471
493
|
}
|
|
472
494
|
} else if (returnsModel) {
|
|
473
|
-
lines.push(
|
|
495
|
+
lines.push(
|
|
496
|
+
` return yield* ODataOps.executeV4ActionEntity(client, config, url, ${operation.returnType.typeMapping.tsType}, ${bodyArg})`
|
|
497
|
+
)
|
|
474
498
|
} else {
|
|
475
499
|
// Primitive return - use entity with schema
|
|
476
|
-
lines.push(
|
|
500
|
+
lines.push(
|
|
501
|
+
` return yield* ODataOps.executeV4FunctionPrimitive(client, config, url, ${operation.returnType.typeMapping.effectSchema})`
|
|
502
|
+
)
|
|
477
503
|
}
|
|
478
504
|
}
|
|
479
505
|
|