@medyll/idae-machine 0.124.0 → 0.125.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.
Files changed (36) hide show
  1. package/dist/form/CreateUpdate.svelte +2 -1
  2. package/dist/index.d.ts +18 -11
  3. package/dist/index.js +18 -11
  4. package/dist/main/machine/IDbCollection.d.ts +71 -0
  5. package/dist/main/machine/IDbCollection.js +102 -0
  6. package/dist/main/machine/IDbCollectionFieldForge.d.ts +42 -0
  7. package/dist/main/machine/IDbCollectionFieldForge.js +74 -0
  8. package/dist/main/machine/IDbCollectionFieldValues.d.ts +57 -0
  9. package/dist/main/machine/IDbCollectionFieldValues.js +82 -0
  10. package/dist/main/machine/IDbCollectionValues.d.ts +78 -0
  11. package/dist/main/machine/IDbCollectionValues.js +203 -0
  12. package/dist/main/machine/IDbError.d.ts +6 -0
  13. package/dist/main/machine/IDbError.js +61 -0
  14. package/dist/main/machine/IDbFormValidate.d.ts +55 -0
  15. package/dist/main/machine/IDbFormValidate.js +183 -0
  16. package/dist/main/machine/IDbValidationError.d.ts +19 -0
  17. package/dist/main/machine/IDbValidationError.js +24 -0
  18. package/dist/main/machineDb.d.ts +18 -222
  19. package/dist/main/machineDb.js +60 -653
  20. package/dist/main/machineForge.d.ts +57 -0
  21. package/dist/main/machineForge.js +105 -0
  22. package/dist/{form → ui}/CollectionButton.svelte +2 -2
  23. package/dist/{form → ui}/CollectionButton.svelte.d.ts +1 -1
  24. package/dist/{form → ui}/CollectionFks.svelte +3 -5
  25. package/dist/{form → ui}/CollectionList.svelte +1 -1
  26. package/dist/{form → ui}/CollectionListMenu.svelte +3 -2
  27. package/package.json +3 -3
  28. package/dist/form/DataList.svelte +0 -60
  29. package/dist/form/DataList.svelte.d.ts +0 -10
  30. /package/dist/{form → ui}/CollectionFieldGuess.svelte +0 -0
  31. /package/dist/{form → ui}/CollectionFieldGuess.svelte.d.ts +0 -0
  32. /package/dist/{form → ui}/CollectionFks.svelte.d.ts +0 -0
  33. /package/dist/{form → ui}/CollectionList.svelte.d.ts +0 -0
  34. /package/dist/{form → ui}/CollectionListMenu.svelte.d.ts +0 -0
  35. /package/dist/{form → ui}/CollectionReverseFks.svelte +0 -0
  36. /package/dist/{form → ui}/CollectionReverseFks.svelte.d.ts +0 -0
@@ -0,0 +1,57 @@
1
+ import type { TplCollectionName, TplFields } from "@medyll/idae-idbql";
2
+ import type { IDbFieldType, IDbFieldRules, IDbForgeArgs } from "./machineDb.js";
3
+ /**
4
+ * Represents the structure for database field forging.
5
+ * Used to describe and construct database field definitions dynamically.
6
+ */
7
+ export type IDbForge = {
8
+ /** Name of the collection (table) */
9
+ collection?: TplCollectionName;
10
+ /** Name of the field within the collection */
11
+ fieldName?: keyof TplFields;
12
+ /** Type of the field (e.g., string, number, fk, array, etc.) */
13
+ fieldType?: IDbFieldType;
14
+ /** Field rule string describing the type and constraints */
15
+ fieldRule?: IDbFieldRules;
16
+ /** Additional arguments for the field (properties, options, etc.) */
17
+ fieldArgs?: IDbForgeArgs | undefined;
18
+ /** The resolved type (array, object, fk, primitive) */
19
+ is: unknown;
20
+ };
21
+ /**
22
+ * Utility class for parsing and constructing database field definitions (IDbForge).
23
+ * Provides methods to analyze field rules and extract type information for schema generation.
24
+ */
25
+ export declare class MachineForge {
26
+ /**
27
+ * Create a new MachineForge instance.
28
+ */
29
+ constructor();
30
+ /**
31
+ * Test if a field rule matches a specific type (array, object, fk, primitive).
32
+ * @param what - The type to test for ("array", "object", "fk", "primitive").
33
+ * @param fieldRule - The field rule string to analyze.
34
+ * @returns Partial IDbForge object if the rule matches, otherwise undefined.
35
+ */
36
+ testIs(what: "array" | "object" | "fk" | "primitive", fieldRule: IDbFieldRules): Partial<IDbForge> | undefined;
37
+ /**
38
+ * Returns a partial IDbForge object for the given type and field rule.
39
+ * @param what - The type to extract ("array", "object", "fk", "primitive").
40
+ * @param fieldRule - The field rule string to analyze.
41
+ * @returns Partial IDbForge object with extracted type info.
42
+ */
43
+ is(what: "array" | "object" | "fk" | "primitive", fieldRule: IDbFieldRules): Partial<IDbForge>;
44
+ /**
45
+ * Extracts type, rule, and argument information from a field rule string.
46
+ * @param type - The type to extract ("array", "object", "fk", "primitive").
47
+ * @param fieldRule - The field rule string to analyze.
48
+ * @returns Partial IDbForge object with extracted details.
49
+ */
50
+ extract(type: "array" | "object" | "fk" | "primitive", fieldRule: IDbFieldRules): Partial<IDbForge>;
51
+ /**
52
+ * Constructs an IDbForge object from its components.
53
+ * @param params - The components of the IDbForge object.
54
+ * @returns A complete IDbForge object.
55
+ */
56
+ forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is, }: IDbForge): IDbForge;
57
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Utility class for parsing and constructing database field definitions (IDbForge).
3
+ * Provides methods to analyze field rules and extract type information for schema generation.
4
+ */
5
+ export class MachineForge {
6
+ /**
7
+ * Create a new MachineForge instance.
8
+ */
9
+ constructor() { }
10
+ /**
11
+ * Test if a field rule matches a specific type (array, object, fk, primitive).
12
+ * @param what - The type to test for ("array", "object", "fk", "primitive").
13
+ * @param fieldRule - The field rule string to analyze.
14
+ * @returns Partial IDbForge object if the rule matches, otherwise undefined.
15
+ */
16
+ testIs(what, fieldRule) {
17
+ const typeMappings = {
18
+ fk: "fk-",
19
+ array: "array-of-",
20
+ object: "object-",
21
+ primitive: "",
22
+ };
23
+ const prefix = typeMappings[what];
24
+ // For primitive, ensure it does not start with any other type prefix
25
+ if (what === "primitive") {
26
+ if (!fieldRule.startsWith("array-of-") &&
27
+ !fieldRule.startsWith("object-") &&
28
+ !fieldRule.startsWith("fk-")) {
29
+ return this.is(what, fieldRule);
30
+ }
31
+ return undefined;
32
+ }
33
+ // For other types, check if the rule starts with the expected prefix
34
+ if (fieldRule.startsWith(prefix)) {
35
+ return this.is(what, fieldRule);
36
+ }
37
+ return undefined;
38
+ }
39
+ /**
40
+ * Returns a partial IDbForge object for the given type and field rule.
41
+ * @param what - The type to extract ("array", "object", "fk", "primitive").
42
+ * @param fieldRule - The field rule string to analyze.
43
+ * @returns Partial IDbForge object with extracted type info.
44
+ */
45
+ is(what, fieldRule) {
46
+ return this.extract(what, fieldRule);
47
+ }
48
+ /**
49
+ * Extracts type, rule, and argument information from a field rule string.
50
+ * @param type - The type to extract ("array", "object", "fk", "primitive").
51
+ * @param fieldRule - The field rule string to analyze.
52
+ * @returns Partial IDbForge object with extracted details.
53
+ */
54
+ extract(type, fieldRule) {
55
+ /**
56
+ * Helper to extract the substring after a given pattern, before any arguments.
57
+ * @param pattern - The prefix pattern to remove.
58
+ * @param source - The field rule string.
59
+ * @returns The substring after the pattern.
60
+ */
61
+ function extractAfter(pattern, source) {
62
+ const reg = source?.split("(")?.[0];
63
+ return reg.split(pattern)[1];
64
+ }
65
+ /**
66
+ * Helper to extract the main type and argument list from a field rule string.
67
+ * @param source - The field rule string.
68
+ * @returns Object with the main type (piece) and argument array (args).
69
+ */
70
+ function extractArgs(source) {
71
+ const [piece, remaining] = source.split("(");
72
+ if (!remaining)
73
+ return { piece: piece.trim(), args: undefined };
74
+ const [central] = remaining?.split(")");
75
+ const args = central?.split(" ");
76
+ return { piece: piece.trim(), args };
77
+ }
78
+ const extractedArgs = extractArgs(fieldRule);
79
+ let fieldType;
80
+ const fieldArgs = extractedArgs?.args;
81
+ switch (type) {
82
+ case "array":
83
+ fieldType = extractAfter("array-of-", fieldRule);
84
+ break;
85
+ case "object":
86
+ fieldType = extractAfter("object-", fieldRule);
87
+ break;
88
+ case "fk":
89
+ fieldType = "fk-" + extractAfter("fk-", fieldRule);
90
+ break;
91
+ case "primitive":
92
+ fieldType = extractedArgs?.piece;
93
+ break;
94
+ }
95
+ return { fieldType, fieldRule, fieldArgs, is: type };
96
+ }
97
+ /**
98
+ * Constructs an IDbForge object from its components.
99
+ * @param params - The components of the IDbForge object.
100
+ * @returns A complete IDbForge object.
101
+ */
102
+ forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is, }) {
103
+ return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
104
+ }
105
+ }
@@ -4,8 +4,8 @@
4
4
  -->
5
5
  <script lang="ts" generics="COL">
6
6
  import { Button, openWindow } from '@medyll/idae-slotui-svelte';
7
- import CreateUpdate from './CreateUpdate.svelte';
8
- import { type CreateUpdateProps } from './types';
7
+ import CreateUpdate from '../form/CreateUpdate.svelte';
8
+ import { type CreateUpdateProps } from '../form/types.js';
9
9
 
10
10
  type CollectionButtonProps = {
11
11
  collection: string;
@@ -1,4 +1,4 @@
1
- import { type CreateUpdateProps } from './types';
1
+ import { type CreateUpdateProps } from '../form/types.js';
2
2
  type CollectionButtonProps = {
3
3
  collection: string;
4
4
  withData?: Record<string, any>;
@@ -10,13 +10,11 @@
10
10
  collectionId?: any;
11
11
  where?: Where;
12
12
  };
13
- let { collection }: CollectionFksProps = $props();
14
13
 
15
- // idbqlState[fkCollection].get(fkId);
14
+ let { collection,collectionId,where }: CollectionFksProps = $props();
16
15
 
17
- const dbFields = machine.collections;
18
- const collections = new MachineDb(schemeModel);
19
- const fks = $derived(collections.fks(collection));
16
+
17
+ const fks = $derived(machine.collections.fks(collection));
20
18
  </script>
21
19
 
22
20
  <Looper data={Object.entries(fks)}>
@@ -8,7 +8,7 @@
8
8
  type Props,
9
9
  Looper
10
10
  } from '@medyll/idae-slotui-svelte';
11
- import CreateUpdate from './CreateUpdate.svelte';
11
+ import CreateUpdate from '../form/CreateUpdate.svelte';
12
12
  import { hydrate, type Snippet } from 'svelte';
13
13
  import type { Where } from '@medyll/idae-idbql';
14
14
 
@@ -1,8 +1,9 @@
1
1
  <script lang="ts" generics="COL = Record<string,any>">
2
2
  import { type MenuListProps, Button, MenuList, MenuListItem, openWindow, type Props } from '@medyll/idae-slotui-svelte';
3
- import CreateUpdate from './CreateUpdate.svelte';
3
+ import CreateUpdate from '../form/CreateUpdate.svelte';
4
4
  import { idbqlState } from '../db/dbSchema.js';
5
- import { MachineDb, IDbCollectionValues } from '../main/machineDb.js';
5
+ import { MachineDb } from '../main/machineDb.js';
6
+ import { IDbCollectionValues } from '../main/IDbCollectionValues';
6
7
  import { hydrate } from 'svelte';
7
8
  import type { Where } from '@medyll/idae-idbql';
8
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medyll/idae-machine",
3
- "version": "0.124.0",
3
+ "version": "0.125.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -49,8 +49,8 @@
49
49
  "scope": "@medyll",
50
50
  "dependencies": {
51
51
  "@huggingface/prettier-plugin-vertical-align": "^0.2.3",
52
- "@medyll/idae-slotui-svelte": "0.177.0",
53
- "@medyll/idae-idbql": "0.174.0"
52
+ "@medyll/idae-slotui-svelte": "0.178.0",
53
+ "@medyll/idae-idbql": "0.175.0"
54
54
  },
55
55
  "scripts": {
56
56
  "dev": "vite dev",
@@ -1,60 +0,0 @@
1
- <!-- DataList.svelte - Composant listant les items d'une collection
2
- Migré depuis _work, adapté pour /lib/form et Svelte 5
3
- Props : collection, displayMode, where, items, onItemClick
4
- -->
5
- <script lang="ts">
6
- let {
7
- collection,
8
- displayMode = 'grid',
9
- where = {},
10
- items = [],
11
- onItemClick = null
12
- }: {
13
- collection: string,
14
- displayMode?: 'grid' | 'list',
15
- where?: any,
16
- items?: any[],
17
- onItemClick?: ((item: any, idx: number) => void) | null
18
- } = $props();
19
- </script>
20
-
21
- <div class="data-list" data-mode={displayMode}>
22
- <h2>{collection} ({displayMode})</h2>
23
- <div class={displayMode === 'grid' ? 'grid' : 'list'}>
24
- {#each items as item, idx}
25
- <div
26
- class="item"
27
- role="button"
28
- tabindex="0"
29
- onclick={() => onItemClick && onItemClick(item, idx)}
30
- onkeydown={e => (e.key === 'Enter' || e.key === ' ') && onItemClick && onItemClick(item, idx)}
31
- >
32
- {item.name || `Item ${idx+1}`}
33
- </div>
34
- {:else}
35
- <p>No items to display.</p>
36
- {/each}
37
- </div>
38
- </div>
39
-
40
- <style>
41
- .data-list {
42
- padding: 1rem;
43
- }
44
- .grid {
45
- display: grid;
46
- grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
47
- gap: 1rem;
48
- }
49
- .list {
50
- display: flex;
51
- flex-direction: column;
52
- gap: 0.5rem;
53
- }
54
- .item {
55
- background: #f0f0f0;
56
- border-radius: 6px;
57
- padding: 0.75rem;
58
- cursor: pointer;
59
- }
60
- </style>
@@ -1,10 +0,0 @@
1
- type $$ComponentProps = {
2
- collection: string;
3
- displayMode?: 'grid' | 'list';
4
- where?: any;
5
- items?: any[];
6
- onItemClick?: ((item: any, idx: number) => void) | null;
7
- };
8
- declare const DataList: import("svelte").Component<$$ComponentProps, {}, "">;
9
- type DataList = ReturnType<typeof DataList>;
10
- export default DataList;
File without changes
File without changes
File without changes
File without changes