@dialecte/create 0.0.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 (52) hide show
  1. package/README.md +88 -0
  2. package/dist/cli/index.js +281 -0
  3. package/package.json +43 -0
  4. package/python/generate/__init__.py +1 -0
  5. package/python/generate/__main__.py +103 -0
  6. package/python/generate/collector.py +128 -0
  7. package/python/generate/deriver.py +117 -0
  8. package/python/generate/emitters/__init__.py +1 -0
  9. package/python/generate/emitters/constants.py +69 -0
  10. package/python/generate/emitters/definition.py +49 -0
  11. package/python/generate/emitters/ts_helpers.py +283 -0
  12. package/python/generate/emitters/types.py +67 -0
  13. package/python/generate/extractors/__init__.py +1 -0
  14. package/python/generate/extractors/attributes.py +83 -0
  15. package/python/generate/extractors/children.py +175 -0
  16. package/python/generate/extractors/constraints.py +154 -0
  17. package/python/generate/extractors/docs.py +32 -0
  18. package/python/generate/extractors/facets.py +168 -0
  19. package/python/generate/extractors/namespace.py +59 -0
  20. package/python/generate/globals.py +99 -0
  21. package/python/generate/helpers.py +143 -0
  22. package/python/generate/ir.py +81 -0
  23. package/python/generate/orphans.py +69 -0
  24. package/python/generate/xpath_parser.py +167 -0
  25. package/python/generate/xsi_type.py +150 -0
  26. package/python/pyproject.toml +15 -0
  27. package/templates/dialecte/README.md +39 -0
  28. package/templates/dialecte/_gitignore +4 -0
  29. package/templates/dialecte/docs/.vitepress/config.ts +15 -0
  30. package/templates/dialecte/docs/index.md +18 -0
  31. package/templates/dialecte/env.d.ts +1 -0
  32. package/templates/dialecte/package.json +45 -0
  33. package/templates/dialecte/src/__version__/config/dialecte.config.ts +48 -0
  34. package/templates/dialecte/src/__version__/config/hydrated.types.ts +78 -0
  35. package/templates/dialecte/src/__version__/config/index.ts +2 -0
  36. package/templates/dialecte/src/__version__/config/namespaces.ts +6 -0
  37. package/templates/dialecte/src/__version__/definition/.gitkeep +2 -0
  38. package/templates/dialecte/src/__version__/definition/index.ts +4 -0
  39. package/templates/dialecte/src/__version__/dialecte.ts +30 -0
  40. package/templates/dialecte/src/__version__/extensions/index.ts +3 -0
  41. package/templates/dialecte/src/__version__/index.ts +2 -0
  42. package/templates/dialecte/src/__version__/test/hydrated-test.ts +53 -0
  43. package/templates/dialecte/src/__version__/test/index.ts +1 -0
  44. package/templates/dialecte/src/index.ts +1 -0
  45. package/templates/dialecte/tsconfig.build.json +24 -0
  46. package/templates/dialecte/tsconfig.json +8 -0
  47. package/templates/dialecte/tsconfig.node.json +13 -0
  48. package/templates/dialecte/tsconfig.vitest.json +10 -0
  49. package/templates/dialecte/vite.config.ts +36 -0
  50. package/templates/dialecte/vitest.config.ts +35 -0
  51. package/vendor/elementpath-5.1.1-py3-none-any.whl +0 -0
  52. package/vendor/xmlschema-4.3.1-py3-none-any.whl +0 -0
@@ -0,0 +1,18 @@
1
+ # **packageName**
2
+
3
+ Dialecte SDK for `__dialecteId__`, generated with [`@dialecte/create`](https://github.com/dialecte/create).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install __packageName__ @dialecte/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { create__DialecteName__Project } from '__packageName__/__version__'
15
+
16
+ const project = create__DialecteName__Project()
17
+ await project.open('my-project')
18
+ ```
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "__packageName__",
3
+ "version": "0.0.1",
4
+ "description": "Dialecte SDK for __dialecteId__",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "source": "src/index.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ "./__version__": {
13
+ "types": "./dist/__version__/index.d.ts",
14
+ "default": "./dist/__version__/index.js"
15
+ },
16
+ "./__version__/test": {
17
+ "types": "./dist/__version__/test.d.ts",
18
+ "default": "./dist/__version__/test.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "run-p type-check \"build-only {@}\" --",
23
+ "build-only": "tsc -p tsconfig.json && vite build",
24
+ "type-check": "tsc --noEmit",
25
+ "test": "vitest",
26
+ "doc:dev": "vitepress dev docs",
27
+ "doc:build": "vitepress build docs",
28
+ "doc:preview": "vitepress preview docs"
29
+ },
30
+ "dependencies": {
31
+ "@dialecte/core": "__coreVersion__"
32
+ },
33
+ "devDependencies": {
34
+ "@tsconfig/node24": "^24.0.4",
35
+ "@types/node": "^24.12.4",
36
+ "@vitest/browser-playwright": "^4.1.8",
37
+ "npm-run-all2": "^8.0.4",
38
+ "playwright": "^1.60.0",
39
+ "typescript": "^6.0.3",
40
+ "vite": "^8.0.16",
41
+ "vite-plugin-dts": "^5.0.2",
42
+ "vitepress": "^2.0.0-alpha.17",
43
+ "vitest": "^4.1.8"
44
+ }
45
+ }
@@ -0,0 +1,48 @@
1
+ import {
2
+ DEFINITION,
3
+ ELEMENT_NAMES,
4
+ ATTRIBUTES,
5
+ CHILDREN,
6
+ PARENTS,
7
+ DESCENDANTS,
8
+ ANCESTORS,
9
+ ROOT_ELEMENT,
10
+ SINGLETON_ELEMENTS,
11
+ } from '../definition'
12
+ import { __DIALECTE_NAME___NAMESPACES } from './namespaces'
13
+
14
+ import type { IOConfig, AnyDialecteConfig, DatabaseConfig } from '@dialecte/core'
15
+
16
+ // __DialecteName__-specific IO configuration
17
+ export const __DIALECTE_NAME___IO_CONFIG = {
18
+ supportedFileExtensions: ['.xml'],
19
+ } as const satisfies IOConfig
20
+
21
+ // __DialecteName__ database configuration
22
+ export const __DIALECTE_NAME___DATABASE_CONFIG = {
23
+ recordSchema: {
24
+ primaryKey: 'id',
25
+ indexes: ['tagName', 'parent.id', 'parent.tagName'],
26
+ compoundIndexes: [['id', 'tagName']],
27
+ arrayIndexes: ['children.id', 'children.tagName'],
28
+ },
29
+ } as const satisfies DatabaseConfig
30
+
31
+ export { __DIALECTE_NAME___NAMESPACES }
32
+
33
+ export const __DIALECTE_NAME___DIALECTE_CONFIG = {
34
+ singletonElements: SINGLETON_ELEMENTS,
35
+ elements: ELEMENT_NAMES,
36
+ namespaces: __DIALECTE_NAME___NAMESPACES,
37
+ attributes: ATTRIBUTES,
38
+ children: CHILDREN,
39
+ parents: PARENTS,
40
+ descendants: DESCENDANTS,
41
+ ancestors: ANCESTORS,
42
+ database: __DIALECTE_NAME___DATABASE_CONFIG,
43
+ io: __DIALECTE_NAME___IO_CONFIG,
44
+ definition: DEFINITION,
45
+ rootElementName: ROOT_ELEMENT,
46
+ } as const satisfies AnyDialecteConfig
47
+
48
+ export type Config = Readonly<typeof __DIALECTE_NAME___DIALECTE_CONFIG>
@@ -0,0 +1,78 @@
1
+ import type { Config } from './dialecte.config'
2
+ import type { __DIALECTE_NAME___EXTENSION_MODULES } from '@/__version__/extensions'
3
+ import type * as Core from '@dialecte/core'
4
+
5
+ type __DialecteName__Extensions = Core.MergedExtensions<typeof __DIALECTE_NAME___EXTENSION_MODULES>
6
+
7
+ export namespace __DialecteName__ {
8
+ export type Project<GenericCustomModules extends Core.ExtensionModules = Record<never, never>> =
9
+ Core.Project<Config, __DialecteName__Extensions & GenericCustomModules>
10
+ export type Document = Core.Document<Config, __DialecteName__Extensions>
11
+ export type Context = Core.Context<Config>
12
+
13
+ export type Query = Core.Query<Config> & Core.QueryExtensions<__DialecteName__Extensions>
14
+ export type Transaction = Core.Transaction<Config> &
15
+ Core.AllExtensions<__DialecteName__Extensions>
16
+ export type TransactionHooks = Core.TransactionHooks<Config>
17
+
18
+ // DEFINITION
19
+ export type ElementsOf = Core.ElementsOf<Config>
20
+ export type Ref<GenericElement extends ElementsOf> = Core.Ref<Config, GenericElement>
21
+ export type AttributesValueObjectOf<GenericElement extends ElementsOf> =
22
+ Core.AttributesValueObjectOf<Config, GenericElement>
23
+ export type AttributesOf<GenericElement extends ElementsOf> = Core.AttributesOf<
24
+ Config,
25
+ GenericElement
26
+ >
27
+ export type FullAttributeObjectOf<GenericElement extends ElementsOf> = Core.FullAttributeObjectOf<
28
+ Config,
29
+ GenericElement
30
+ >
31
+ export type ChildrenOf<GenericElement extends ElementsOf> = Core.ChildrenOf<
32
+ Config,
33
+ GenericElement
34
+ >
35
+ export type ParentsOf<GenericElement extends ElementsOf> = Core.ParentsOf<Config, GenericElement>
36
+ export type DescendantsOf<GenericElement extends ElementsOf> = Core.DescendantsOf<
37
+ Config,
38
+ GenericElement
39
+ >
40
+ export type AncestorsOf<GenericElement extends ElementsOf> = Core.AncestorsOf<
41
+ Config,
42
+ GenericElement
43
+ >
44
+ export type RootElementOf = Core.RootElementOf<Config>
45
+ export type SingletonElementsOf = Core.SingletonElementsOf<Config>
46
+
47
+ // OPERATIONS
48
+ export type Operation = Core.Operation<Config>
49
+
50
+ // RECORDS
51
+ export type RawRecord<GenericElement extends ElementsOf> = Core.RawRecord<Config, GenericElement>
52
+ export type TrackedRecord<GenericElement extends ElementsOf> = Core.TrackedRecord<
53
+ Config,
54
+ GenericElement
55
+ >
56
+ export type TreeRecord<GenericElement extends ElementsOf> = Core.TreeRecord<
57
+ Config,
58
+ GenericElement
59
+ >
60
+
61
+ export type ParentRelationship<GenericElement extends ElementsOf> = Core.ParentRelationship<
62
+ Config,
63
+ GenericElement
64
+ >
65
+ export type ChildRelationship<GenericElement extends ElementsOf> = Core.ChildRelationship<
66
+ Config,
67
+ GenericElement
68
+ >
69
+
70
+ export type Attribute<GenericElement extends ElementsOf> = Core.Attribute<Config, GenericElement>
71
+ export type QualifiedAttribute<GenericElement extends ElementsOf> = Core.QualifiedAttribute<
72
+ Config,
73
+ GenericElement
74
+ >
75
+
76
+ // MISCELLANEOUS
77
+ export type CloneMapping = Core.CloneMapping<Config>
78
+ }
@@ -0,0 +1,2 @@
1
+ export * from './dialecte.config'
2
+ export type * from './hydrated.types'
@@ -0,0 +1,6 @@
1
+ import { XSI_NAMESPACE } from '@dialecte/core/helpers'
2
+
3
+ export const __DIALECTE_NAME___NAMESPACES = {
4
+ default: { uri: '__namespaceUri__', prefix: '' },
5
+ xsi: XSI_NAMESPACE,
6
+ } as const
@@ -0,0 +1,2 @@
1
+ # Generated definition files are written here by `@dialecte/create`
2
+ # (definition.generated.ts, constants.generated.ts, types.generated.ts).
@@ -0,0 +1,4 @@
1
+ export * from './constants.generated'
2
+ export * from './definition.generated'
3
+
4
+ export type * from './types.generated'
@@ -0,0 +1,30 @@
1
+ import { __DialecteName__ } from './config'
2
+ import { __DIALECTE_NAME___DIALECTE_CONFIG } from './config/dialecte.config'
3
+ import { __DIALECTE_NAME___EXTENSION_MODULES } from './extensions'
4
+
5
+ import { Project } from '@dialecte/core'
6
+
7
+ import type { StorageParam, ExtensionModules } from '@dialecte/core'
8
+
9
+ /**
10
+ * Create a __DialecteName__ project with pre-configured config and extensions.
11
+ * Call .open(name) to initialize the store and hydrate state.
12
+ */
13
+ export function create__DialecteName__Project<
14
+ CustomModules extends ExtensionModules = Record<never, never>,
15
+ >(params?: {
16
+ storage?: StorageParam
17
+ extensions?: CustomModules
18
+ }): __DialecteName__.Project<CustomModules> {
19
+ const { storage = { type: 'local' }, extensions } = params ?? {}
20
+
21
+ return new Project({
22
+ configs: { __dialecteId__: __DIALECTE_NAME___DIALECTE_CONFIG },
23
+ defaultConfigKey: '__dialecteId__',
24
+ storage,
25
+ extensions: {
26
+ base: __DIALECTE_NAME___EXTENSION_MODULES,
27
+ custom: extensions,
28
+ },
29
+ }) as __DialecteName__.Project<CustomModules>
30
+ }
@@ -0,0 +1,3 @@
1
+ const __DIALECTE_NAME___EXTENSION_MODULES = {}
2
+
3
+ export { __DIALECTE_NAME___EXTENSION_MODULES }
@@ -0,0 +1,2 @@
1
+ export * from './dialecte'
2
+ export * from './config'
@@ -0,0 +1,53 @@
1
+ import {
2
+ CUSTOM_RECORD_ID_ATTRIBUTE,
3
+ CUSTOM_RECORD_ID_ATTRIBUTE_NAME,
4
+ XMLNS_XSI_NAMESPACE,
5
+ } from '@dialecte/core/helpers'
6
+ import {
7
+ createTestProject,
8
+ createTestRecordFactory,
9
+ createXmlAssertions,
10
+ createTestRunner,
11
+ XMLNS_DEV_NAMESPACE,
12
+ } from '@dialecte/core/test'
13
+
14
+ import { __DIALECTE_NAME___DIALECTE_CONFIG } from '@/__version__/config'
15
+ import { __DIALECTE_NAME___EXTENSION_MODULES } from '@/__version__/extensions'
16
+
17
+ import type { Config } from '@/__version__/config/dialecte.config'
18
+
19
+ type __DialecteName__Modules = typeof __DIALECTE_NAME___EXTENSION_MODULES
20
+
21
+ export const XMLNS___DIALECTE_NAME___NAMESPACE = `xmlns="${__DIALECTE_NAME___DIALECTE_CONFIG.namespaces.default.uri}"`
22
+ export const ALL_XMLNS_NAMESPACES = `${XMLNS___DIALECTE_NAME___NAMESPACE} ${XMLNS_DEV_NAMESPACE} ${XMLNS_XSI_NAMESPACE}`
23
+ export { CUSTOM_RECORD_ID_ATTRIBUTE, CUSTOM_RECORD_ID_ATTRIBUTE_NAME }
24
+
25
+ const __DIALECTE_NAME___EXTENSIONS = { base: __DIALECTE_NAME___EXTENSION_MODULES }
26
+
27
+ export const run__DialecteName__TestCases = createTestRunner<Config, __DialecteName__Modules>({
28
+ dialecteConfig: __DIALECTE_NAME___DIALECTE_CONFIG,
29
+ extensions: __DIALECTE_NAME___EXTENSIONS,
30
+ })
31
+
32
+ export async function create__DialecteName__TestProject(params: {
33
+ sourceXml: string
34
+ targetXml?: string
35
+ }) {
36
+ const { sourceXml, targetXml } = params
37
+
38
+ return createTestProject<Config, __DialecteName__Modules>({
39
+ sourceXml,
40
+ targetXml,
41
+ dialecteConfig: __DIALECTE_NAME___DIALECTE_CONFIG,
42
+ extensions: __DIALECTE_NAME___EXTENSIONS,
43
+ })
44
+ }
45
+
46
+ export const create__DialecteName__TestRecord: ReturnType<typeof createTestRecordFactory<Config>> =
47
+ createTestRecordFactory<Config>(__DIALECTE_NAME___DIALECTE_CONFIG)
48
+
49
+ export const { assertExpectedElementQueries, assertUnexpectedElementQueries } = createXmlAssertions(
50
+ {
51
+ namespaces: __DIALECTE_NAME___DIALECTE_CONFIG.namespaces,
52
+ },
53
+ )
@@ -0,0 +1 @@
1
+ export * from './hydrated-test'
@@ -0,0 +1 @@
1
+ export * from './__version__/dialecte'
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": "@tsconfig/node24/tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "declaration": true,
6
+ "declarationMap": true,
7
+ "emitDeclarationOnly": true,
8
+ "outDir": "dist",
9
+ "rootDir": "src",
10
+ "module": "ESNext",
11
+ "target": "ES2019",
12
+ "moduleResolution": "Bundler",
13
+ "esModuleInterop": true,
14
+ "strict": true,
15
+ "skipLibCheck": true,
16
+ "lib": ["ESNext", "DOM"],
17
+ "resolveJsonModule": true,
18
+ "paths": {
19
+ "@/*": ["./src/*"]
20
+ }
21
+ },
22
+ "include": ["src/**/*"],
23
+ "exclude": ["**/*.test.ts", "**/__tests__/**"]
24
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.node.json" },
5
+ { "path": "./tsconfig.vitest.json" },
6
+ { "path": "./tsconfig.build.json" }
7
+ ]
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@tsconfig/node24/tsconfig.json",
3
+ "include": ["vite.config.*", "vitest.config.*"],
4
+ "compilerOptions": {
5
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
6
+ "module": "ESNext",
7
+ "moduleResolution": "Bundler",
8
+ "types": ["node"],
9
+ "paths": {
10
+ "@/*": ["./src/*"]
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.node.json",
3
+ "include": ["src/**/*.test.ts", "env.d.ts"],
4
+ "exclude": [],
5
+ "compilerOptions": {
6
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",
7
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
8
+ "types": ["node"]
9
+ }
10
+ }
@@ -0,0 +1,36 @@
1
+ import path from 'node:path'
2
+ /// <reference types="vite/client" />
3
+ import { fileURLToPath, URL } from 'node:url'
4
+
5
+ import { defineConfig } from 'vite'
6
+ import dts from 'vite-plugin-dts'
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ dts({
11
+ tsconfigPath: path.resolve(__dirname, './tsconfig.build.json'),
12
+ insertTypesEntry: true,
13
+ }),
14
+ ],
15
+ resolve: {
16
+ alias: {
17
+ '@': fileURLToPath(new URL('./src', import.meta.url)),
18
+ },
19
+ },
20
+ build: {
21
+ sourcemap: import.meta.env?.DEV,
22
+ lib: {
23
+ entry: {
24
+ '__version__/index': fileURLToPath(new URL('./src/__version__/index.ts', import.meta.url)),
25
+ '__version__/test': fileURLToPath(
26
+ new URL('./src/__version__/test/index.ts', import.meta.url),
27
+ ),
28
+ },
29
+ name: '__DialecteName__Dialecte',
30
+ formats: ['es'],
31
+ },
32
+ rollupOptions: {
33
+ external: [/^@dialecte\/core/],
34
+ },
35
+ },
36
+ })
@@ -0,0 +1,35 @@
1
+ import { fileURLToPath } from 'node:url'
2
+
3
+ import viteConfig from './vite.config'
4
+
5
+ import { playwright } from '@vitest/browser-playwright'
6
+ import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
7
+
8
+ export default mergeConfig(
9
+ viteConfig,
10
+ defineConfig({
11
+ test: {
12
+ watch: false,
13
+ testTimeout: 5_000,
14
+ projects: [
15
+ {
16
+ resolve: viteConfig.resolve,
17
+ plugins: [],
18
+ test: {
19
+ name: 'unit',
20
+ browser: {
21
+ provider: playwright(),
22
+ enabled: true,
23
+ headless: true,
24
+ instances: [{ browser: 'chromium' }],
25
+ screenshotFailures: false,
26
+ },
27
+ include: ['src/**/*.test.{js,ts,jsx,tsx}'],
28
+ exclude: [...configDefaults.exclude],
29
+ root: fileURLToPath(new URL('./', import.meta.url)),
30
+ },
31
+ },
32
+ ],
33
+ },
34
+ }),
35
+ )