@fjell/core 4.4.0 → 4.4.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.
@@ -0,0 +1,271 @@
1
+ import LibLogger from '../logger.js';
2
+
3
+ const logger = LibLogger.get('KUtils');
4
+ const isItemKeyEqual = (a, b)=>{
5
+ logger.trace('isKeyEqual', {
6
+ a,
7
+ b
8
+ });
9
+ if (isComKey(a) && isComKey(b)) {
10
+ return isComKeyEqual(a, b);
11
+ } else if (isPriKey(a) && isPriKey(b)) {
12
+ if (isComKey(a) || isComKey(b)) {
13
+ return false;
14
+ } else {
15
+ return isPriKeyEqual(a, b);
16
+ }
17
+ } else {
18
+ return false;
19
+ }
20
+ };
21
+ const isPriKeyEqual = (a, b)=>{
22
+ logger.trace('isPriKeyEqual', {
23
+ a,
24
+ b
25
+ });
26
+ return a && b && a.pk === b.pk && a.kt === b.kt;
27
+ };
28
+ const isLocKeyEqual = (a, b)=>{
29
+ logger.trace('isLocKeyEqual', {
30
+ a,
31
+ b
32
+ });
33
+ return a && b && a.lk === b.lk && a.kt === b.kt;
34
+ };
35
+ const isComKeyEqual = (a, b)=>{
36
+ logger.trace('isComKeyEqual', {
37
+ a,
38
+ b
39
+ });
40
+ if (a && b && isPriKeyEqual({
41
+ kt: a.kt,
42
+ pk: a.pk
43
+ }, {
44
+ kt: b.kt,
45
+ pk: b.pk
46
+ })) {
47
+ if (a.loc.length === b.loc.length) {
48
+ for(let i = 0; i < a.loc.length; i++){
49
+ if (!isLocKeyEqual(a.loc[i], b.loc[i])) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ } else {
55
+ return false;
56
+ }
57
+ } else {
58
+ return false;
59
+ }
60
+ };
61
+ const isItemKey = (key)=>{
62
+ logger.trace('isItemKey', {
63
+ key
64
+ });
65
+ return key !== undefined && (isComKey(key) || isPriKey(key));
66
+ };
67
+ const isComKey = (key)=>{
68
+ logger.trace('isComKey', {
69
+ key
70
+ });
71
+ return key !== undefined && key.pk !== undefined && key.kt !== undefined && key.loc !== undefined && key.loc.length > 0;
72
+ };
73
+ const isPriKey = (key)=>{
74
+ logger.trace('isPriKey', {
75
+ key
76
+ });
77
+ return key !== undefined && key.pk !== undefined && key.kt !== undefined && (key.loc === undefined || key.loc.length === 0);
78
+ };
79
+ const isLocKey = (key)=>{
80
+ logger.trace('isLocKey', {
81
+ key
82
+ });
83
+ return key !== undefined && key.lk !== undefined && key.kt !== undefined;
84
+ };
85
+ const generateKeyArray = (key)=>{
86
+ logger.trace('generateKeyArray', {
87
+ key
88
+ });
89
+ const keys = [];
90
+ if (isComKey(key) || isPriKey(key)) {
91
+ // console.log('it is an item key');
92
+ if (isComKey(key)) {
93
+ // console.log('it is a composite key');
94
+ const comKey = key;
95
+ keys.push({
96
+ pk: comKey.pk,
97
+ kt: comKey.kt
98
+ });
99
+ for(let i = 0; i < comKey.loc.length; i++){
100
+ keys.push(comKey.loc[i]);
101
+ }
102
+ } else {
103
+ keys.push(key);
104
+ }
105
+ } else {
106
+ // console.log('is is an array, length: ' + key.length);
107
+ const locKeys = key;
108
+ for(let i = 0; i < locKeys.length; i++){
109
+ // console.log('Pushing a key');
110
+ keys.push(locKeys[i]);
111
+ }
112
+ }
113
+ return keys;
114
+ };
115
+ // TODO: Exactly the same as in ContainedItemLib
116
+ const constructPriKey = (pk, kt)=>{
117
+ logger.trace('constructPriKey', {
118
+ pk,
119
+ kt
120
+ });
121
+ let pri;
122
+ if (typeof pk === 'string') {
123
+ pri = {
124
+ kt: kt,
125
+ pk: pk
126
+ };
127
+ } else {
128
+ pri = pk;
129
+ }
130
+ return pri;
131
+ };
132
+ // TODO: Exactly the same as in ContainedItemLib
133
+ const cPK = constructPriKey;
134
+ const toKeyTypeArray = (ik)=>{
135
+ logger.trace('toKeyTypeArray', {
136
+ ik
137
+ });
138
+ if (isComKey(ik)) {
139
+ const ck = ik;
140
+ return [
141
+ ck.kt,
142
+ ...ck.loc.map((l)=>l.kt)
143
+ ];
144
+ } else {
145
+ return [
146
+ ik.kt
147
+ ];
148
+ }
149
+ };
150
+ const abbrevIK = (ik)=>{
151
+ logger.trace('abbrevIK', {
152
+ ik
153
+ });
154
+ if (ik) {
155
+ if (isComKey(ik)) {
156
+ const ck = ik;
157
+ return `${ck.kt}:${ck.pk}:${ck.loc.map((l)=>`${l.kt}:${l.lk}`).join(',')}`;
158
+ } else {
159
+ return `${ik.kt}:${ik.pk}`;
160
+ }
161
+ } else {
162
+ return 'null IK';
163
+ }
164
+ };
165
+ const abbrevLKA = (keyArray)=>{
166
+ logger.trace('abbrevLKA', {
167
+ keyArray
168
+ });
169
+ if (keyArray === undefined || keyArray === null) {
170
+ return 'null LKA';
171
+ } else {
172
+ return keyArray.map((key)=>{
173
+ if (key) {
174
+ return `${key.kt}:${key.lk}`;
175
+ } else {
176
+ return key;
177
+ }
178
+ }).join(',');
179
+ }
180
+ };
181
+ const primaryType = (ik)=>{
182
+ logger.trace('primaryType', {
183
+ ik
184
+ });
185
+ if (isComKey(ik)) {
186
+ return ik.kt;
187
+ } else {
188
+ return ik.kt;
189
+ }
190
+ };
191
+ /**
192
+ *
193
+ * @param ik ItemKey to be used as a basis for a location
194
+ * @returns
195
+ */ const itemKeyToLocKeyArray = (ik)=>{
196
+ logger.trace('itemKeyToLocKeyArray', {
197
+ ik: abbrevIK(ik)
198
+ });
199
+ let lka = [];
200
+ if (isComKey(ik)) {
201
+ const ck = ik;
202
+ lka = [
203
+ {
204
+ kt: ck.kt,
205
+ lk: ck.pk
206
+ },
207
+ ...ck.loc
208
+ ];
209
+ } else {
210
+ const pk = ik;
211
+ lka = [
212
+ {
213
+ kt: pk.kt,
214
+ lk: pk.pk
215
+ }
216
+ ];
217
+ }
218
+ logger.trace('itemKeyToLocKeyArray Results', {
219
+ ik: abbrevIK(ik),
220
+ lka: abbrevLKA(lka)
221
+ });
222
+ return lka;
223
+ };
224
+ const ikToLKA = itemKeyToLocKeyArray;
225
+ /**
226
+ * Sometimes you need to take a location key array and convert it to the item key that points to the containing item.
227
+ * @param lka A location key array
228
+ * @returns An item key corresponding to the containing item this location refers to.
229
+ */ const locKeyArrayToItemKey = (lka)=>{
230
+ logger.trace('locKeyArrayToItemKey', {
231
+ lka: abbrevLKA(lka)
232
+ });
233
+ if (lka && lka.length === 1) {
234
+ const priKey = cPK(lka[0].lk, lka[0].kt);
235
+ return priKey;
236
+ } else if (lka && lka.length > 1 && lka[0] !== undefined) {
237
+ const locs = lka.slice(1);
238
+ const priKey = cPK(lka[0].lk, lka[0].kt);
239
+ const comKey = {
240
+ kt: priKey.kt,
241
+ pk: priKey.pk,
242
+ loc: locs
243
+ };
244
+ return comKey;
245
+ } else {
246
+ throw new Error('locKeyArrayToItemKey: lka is undefined or empty');
247
+ }
248
+ };
249
+ // TODO: This is annoying that we have to check for '' and 'null'
250
+ const isValidPriKey = (key)=>{
251
+ const valid = key !== undefined && key !== null && key.pk !== undefined && key.pk !== null && key.pk !== '' && key.pk !== 'null' && key.kt !== undefined && key.kt !== null && key.kt !== '' && key.kt !== 'null';
252
+ return valid;
253
+ };
254
+ // TODO: This is annoying that we have to check for '' and 'null'
255
+ const isValidLocKey = (key)=>{
256
+ const valid = key !== undefined && key !== null && key.lk !== undefined && key.lk !== null && key.lk !== '' && key.lk !== 'null' && key.kt !== undefined && key.kt !== null && key.kt !== '' && key.kt !== 'null';
257
+ return valid;
258
+ };
259
+ const isValidLocKeyArray = (keyArray)=>{
260
+ return keyArray !== undefined && keyArray !== null && keyArray.every(isValidLocKey);
261
+ };
262
+ const isValidComKey = (key)=>{
263
+ return key !== undefined && key !== null && isValidPriKey(key) && isValidLocKeyArray(key.loc);
264
+ };
265
+ const isValidItemKey = (key)=>{
266
+ return isComKey(key) && isValidComKey(key) || isPriKey(key) && isValidPriKey(key);
267
+ };
268
+ const lkaToIK = locKeyArrayToItemKey;
269
+
270
+ export { abbrevIK, abbrevLKA, cPK, constructPriKey, generateKeyArray, ikToLKA, isComKey, isComKeyEqual, isItemKey, isItemKeyEqual, isLocKey, isLocKeyEqual, isPriKey, isPriKeyEqual, isValidComKey, isValidItemKey, isValidLocKey, isValidLocKeyArray, isValidPriKey, itemKeyToLocKeyArray, lkaToIK, locKeyArrayToItemKey, primaryType, toKeyTypeArray };
271
+ //# sourceMappingURL=KUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KUtils.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ export type UUID = `${string}-${string}-${string}-${string}-${string}`;
2
+ export interface ComKey<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
3
+ readonly kt: S;
4
+ readonly pk: UUID | string;
5
+ readonly loc: LocKeyArray<L1, L2, L3, L4, L5>;
6
+ }
7
+ export interface PriKey<S extends string> {
8
+ readonly kt: S;
9
+ readonly pk: UUID | string;
10
+ }
11
+ export interface LocKey<L extends string> {
12
+ readonly kt: L;
13
+ readonly lk: UUID | string;
14
+ }
15
+ export type LocKeyArray<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = ([L5] extends [never] ? ([L4] extends [never] ? ([L3] extends [never] ? ([L2] extends [never] ? ([L1] extends [never] ? [
16
+ ] | never : [
17
+ LocKey<L1>
18
+ ]) : [
19
+ LocKey<L1>,
20
+ LocKey<L2>
21
+ ]) : [
22
+ LocKey<L1>,
23
+ LocKey<L2>,
24
+ LocKey<L3>
25
+ ]) : [
26
+ LocKey<L1>,
27
+ LocKey<L2>,
28
+ LocKey<L3>,
29
+ LocKey<L4>
30
+ ]) : [
31
+ LocKey<L1>,
32
+ LocKey<L2>,
33
+ LocKey<L3>,
34
+ LocKey<L4>,
35
+ LocKey<L5>
36
+ ]);
37
+ export type ItemTypeArray<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = ([L5] extends [never] ? ([L4] extends [never] ? ([L3] extends [never] ? ([L2] extends [never] ? ([L1] extends [never] ? [
38
+ S
39
+ ] : [
40
+ S,
41
+ L1
42
+ ]) : [
43
+ S,
44
+ L1,
45
+ L2
46
+ ]) : [
47
+ S,
48
+ L1,
49
+ L2,
50
+ L3
51
+ ]) : [
52
+ S,
53
+ L1,
54
+ L2,
55
+ L3,
56
+ L4
57
+ ]) : [
58
+ S,
59
+ L1,
60
+ L2,
61
+ L3,
62
+ L4,
63
+ L5
64
+ ]);
65
+ export type AllItemTypeArrays<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = readonly [S] | readonly [S, L1] | readonly [S, L1, L2] | readonly [S, L1, L2, L3] | readonly [S, L1, L2, L3, L4] | readonly [S, L1, L2, L3, L4, L5];
66
+ export type AllLocTypeArrays<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = readonly [] | readonly [L1] | readonly [L1, L2] | readonly [L1, L2, L3] | readonly [L1, L2, L3, L4] | readonly [L1, L2, L3, L4, L5];
@@ -0,0 +1,2 @@
1
+ declare const LibLogger: import('@fjell/logging').Logger;
2
+ export default LibLogger;
package/dist/logger.js ADDED
@@ -0,0 +1,6 @@
1
+ import Logging from '@fjell/logging';
2
+
3
+ const LibLogger = Logging.getLogger('@fjell/core');
4
+
5
+ export { LibLogger as default };
6
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fjell/core",
3
3
  "description": "Core Items for Fjell",
4
- "version": "4.4.0",
4
+ "version": "4.4.1",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/src/index.js",
7
7
  "exports": {
package/eslint.config.mjs DELETED
@@ -1,70 +0,0 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import tsParser from "@typescript-eslint/parser";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import js from "@eslint/js";
6
- import { FlatCompat } from "@eslint/eslintrc";
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
10
- const compat = new FlatCompat({
11
- baseDirectory: __dirname,
12
- recommendedConfig: js.configs.recommended,
13
- allConfig: js.configs.all
14
- });
15
-
16
- export default [{
17
- ignores: ["**/dist", "**/node_modules"],
18
- }, ...compat.extends("plugin:@typescript-eslint/recommended"), {
19
- plugins: {
20
- "@typescript-eslint": typescriptEslint,
21
- },
22
-
23
- languageOptions: {
24
- parser: tsParser,
25
- },
26
-
27
- rules: {
28
- "@typescript-eslint/no-unused-expressions": "off",
29
- "no-console": 0,
30
- "no-unused-vars": "off",
31
-
32
- "max-len": ["error", {
33
- code: 120,
34
- }],
35
-
36
- "max-depth": ["error", 4],
37
- "max-params": ["error", 4],
38
- "max-lines": ["error", 500],
39
-
40
- "no-multiple-empty-lines": ["error", {
41
- max: 1,
42
- maxEOF: 1,
43
- }],
44
-
45
- "no-trailing-spaces": ["error", {
46
- skipBlankLines: true,
47
- }],
48
-
49
- indent: ["error", 2, {
50
- SwitchCase: 1,
51
- }],
52
-
53
- "sort-imports": ["error", {
54
- ignoreCase: true,
55
- ignoreDeclarationSort: true,
56
- ignoreMemberSort: false,
57
- memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
58
- }],
59
-
60
- "no-var": "error",
61
- "no-undefined": "error",
62
- "@typescript-eslint/no-unused-vars": "error",
63
- "@typescript-eslint/ban-ts-comment": "off",
64
- "@typescript-eslint/no-explicit-any": "off",
65
-
66
- "no-restricted-imports": ["error", {
67
- patterns: ["..*", "src/*"],
68
- }],
69
- },
70
- }];
package/vite.config.ts DELETED
@@ -1,55 +0,0 @@
1
- import { defineConfig } from 'vite';
2
- import { VitePluginNode } from 'vite-plugin-node';
3
- import dts from 'vite-plugin-dts';
4
- import path from 'path';
5
-
6
- export default defineConfig({
7
- server: {
8
- port: 3000
9
- },
10
- plugins: [
11
- ...VitePluginNode({
12
- adapter: 'express',
13
- appPath: './src/index.ts',
14
- exportName: 'viteNodeApp',
15
- tsCompiler: 'swc',
16
- }),
17
- // visualizer({
18
- // template: 'network',
19
- // filename: 'network.html',
20
- // projectRoot: process.cwd(),
21
- // }),
22
- dts({
23
- entryRoot: 'src',
24
- outDir: 'dist',
25
- exclude: ['./tests/**/*.ts'],
26
- include: ['./src/**/*.ts'],
27
- }),
28
- ],
29
- resolve: {
30
- alias: {
31
- '@': path.resolve(__dirname, './src'),
32
- },
33
- },
34
- build: {
35
- target: 'esnext',
36
- outDir: 'dist',
37
- lib: {
38
- entry: './src/index.ts',
39
- formats: ['es'],
40
- },
41
- rollupOptions: {
42
- input: 'src/index.ts',
43
- output: {
44
- format: 'esm',
45
- entryFileNames: '[name].js',
46
- preserveModules: true,
47
- exports: 'named',
48
- },
49
- },
50
- // Make sure Vite generates ESM-compatible code
51
- modulePreload: false,
52
- minify: false,
53
- sourcemap: true
54
- },
55
- });