jostraca 0.18.0 → 0.20.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.
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrintPoint = exports.FuncPoint = exports.ParallelPoint = exports.SerialPoint = exports.RootPoint = exports.Point = void 0;
4
+ exports.buildPoints = buildPoints;
5
+ exports.makeFuncDef = makeFuncDef;
6
+ const gubu_1 = require("gubu");
7
+ const basic_1 = require("./basic");
8
+ class Point {
9
+ constructor(id, name) {
10
+ this.id = id;
11
+ this.name = name;
12
+ }
13
+ async runner(pctx) {
14
+ const suffix = (null == this.name || '' === this.name) ? '' : ':' + this.name;
15
+ this.logger(pctx, {
16
+ note: this.constructor.name + ':before:' + this.id + suffix, args: this.args
17
+ });
18
+ if (pctx.async) {
19
+ await this.run(pctx);
20
+ }
21
+ else {
22
+ this.run(pctx);
23
+ }
24
+ this.logger(pctx, {
25
+ note: this.constructor.name + ':after:' + this.id + suffix, args: this.args
26
+ });
27
+ }
28
+ logger(pctx, entry) {
29
+ entry.note = null == entry.note ? 'none' : entry.note;
30
+ entry.when = pctx.sys().now();
31
+ entry.depth = pctx.depth;
32
+ if (undefined === entry.args) {
33
+ delete entry.args;
34
+ }
35
+ pctx.log.push(entry);
36
+ }
37
+ }
38
+ exports.Point = Point;
39
+ class SerialPoint extends Point {
40
+ constructor(id) {
41
+ super(id);
42
+ this.points = [];
43
+ }
44
+ add(p) {
45
+ this.points.push(p);
46
+ }
47
+ async run(pctx) {
48
+ let childctx = { ...pctx };
49
+ childctx.depth++;
50
+ for (let p of this.points) {
51
+ if (pctx.async) {
52
+ await p.runner(childctx);
53
+ }
54
+ else {
55
+ p.runner(childctx);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ exports.SerialPoint = SerialPoint;
61
+ class RootPoint extends SerialPoint {
62
+ constructor(id) {
63
+ super(id);
64
+ this.points = [];
65
+ }
66
+ direct(data, sys) {
67
+ const pctx = this.makePointCtx(false, data, sys);
68
+ this.runner(pctx);
69
+ return pctx;
70
+ }
71
+ async start(data, sys) {
72
+ const pctx = this.makePointCtx(true, data, sys);
73
+ await this.runner(pctx);
74
+ return pctx;
75
+ }
76
+ makePointCtx(async, data, sys) {
77
+ const pctx = {
78
+ async,
79
+ log: [],
80
+ data: data || {},
81
+ depth: 0,
82
+ sys: sys || (() => ({
83
+ now: () => Date.now(),
84
+ print: (...s) => {
85
+ if (null != s[0] && 'string' === typeof s[0]) {
86
+ console.dir(s[0], s[1] || { depth: null });
87
+ }
88
+ else {
89
+ console.log(...s);
90
+ }
91
+ }
92
+ }))
93
+ };
94
+ return pctx;
95
+ }
96
+ }
97
+ exports.RootPoint = RootPoint;
98
+ class ParallelPoint extends Point {
99
+ constructor(id) {
100
+ super(id);
101
+ this.points = [];
102
+ }
103
+ add(p) {
104
+ this.points.push(p);
105
+ }
106
+ async run(pctx) {
107
+ let childctx = { ...pctx };
108
+ childctx.depth++;
109
+ await Promise.all(this.points.map(p => p.runner(childctx)));
110
+ }
111
+ }
112
+ exports.ParallelPoint = ParallelPoint;
113
+ class FuncPoint extends Point {
114
+ constructor(id, func) {
115
+ super(id, func.name);
116
+ this.func = func;
117
+ }
118
+ async run(pctx) {
119
+ if (pctx.async) {
120
+ await this.func(pctx);
121
+ }
122
+ else {
123
+ this.func(pctx);
124
+ }
125
+ }
126
+ }
127
+ exports.FuncPoint = FuncPoint;
128
+ class PrintPoint extends Point {
129
+ constructor(id, path) {
130
+ super(id);
131
+ this.path = path;
132
+ }
133
+ async run(pctx) {
134
+ let print = pctx.sys().print;
135
+ let d = pctx.data;
136
+ if (null != this.path) {
137
+ d = (0, basic_1.getx)(d, this.path);
138
+ }
139
+ if (null != d && 'object' === typeof d) {
140
+ print('POINTCTX:');
141
+ print(d);
142
+ }
143
+ else {
144
+ print('POINTCTX: ' + d);
145
+ }
146
+ }
147
+ }
148
+ exports.PrintPoint = PrintPoint;
149
+ const PointDefShape = (0, gubu_1.Gubu)({
150
+ k: (0, gubu_1.Skip)(String),
151
+ n: (0, gubu_1.Skip)(String),
152
+ p: (0, gubu_1.Skip)([]),
153
+ a: (0, gubu_1.Any)(),
154
+ m: {}
155
+ });
156
+ function buildPoints(pdef, pm, id) {
157
+ let idi = 0;
158
+ id = id || (() => (++idi) + '');
159
+ let p = undefined;
160
+ // TODO: fix point kind resolution to be more extensible
161
+ pdef = PointDefShape(pdef);
162
+ let isSerial = 'Serial' === pdef.k || Array.isArray(pdef.p);
163
+ const mp = pm[pdef.k];
164
+ if (null != mp) {
165
+ p = mp(id, pdef);
166
+ }
167
+ else if (null == pdef.k || 'Root' === pdef.k) {
168
+ const rp = new RootPoint(id());
169
+ let cp = pdef.p;
170
+ for (let c of cp) {
171
+ rp.add(buildPoints(c, pm, id));
172
+ }
173
+ p = rp;
174
+ isSerial = false;
175
+ }
176
+ else if ('Parallel' === pdef.k) {
177
+ const sp = new ParallelPoint(id());
178
+ let cp = pdef.p;
179
+ for (let c of cp) {
180
+ sp.add(buildPoints(c, pm, id));
181
+ }
182
+ p = sp;
183
+ isSerial = false;
184
+ }
185
+ if (isSerial) {
186
+ const sp = (p || new SerialPoint(id()));
187
+ let cp = pdef.p;
188
+ for (let c of cp) {
189
+ sp.add(buildPoints(c, pm, id));
190
+ }
191
+ p = sp;
192
+ }
193
+ if (null == p) {
194
+ throw new Error('Unknown point kind: ' + JSON.stringify(pdef));
195
+ }
196
+ return p;
197
+ }
198
+ function makeFuncDef(fd) {
199
+ return (id, pdef) => {
200
+ const fp = new FuncPoint(id(), fd(pdef));
201
+ fp.args = pdef.a;
202
+ return fp;
203
+ };
204
+ }
205
+ //# sourceMappingURL=point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.js","sourceRoot":"","sources":["../../src/util/point.ts"],"names":[],"mappings":";;;AAqSE,kCAAW;AACX,kCAAW;AArSb,+BAAsC;AAEtC,mCAA8B;AAuB9B,MAAe,KAAK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AE,GAAG,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACxC,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAA;QAChB,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jostraca",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "main": "dist/jostraca.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/jostraca.d.ts",
@@ -16,8 +16,8 @@
16
16
  "url": "git://github.com/jostraca/jostraca.git"
17
17
  },
18
18
  "scripts": {
19
- "test": "node --enable-source-maps --test dist-test",
20
- "test-some": "node --enable-source-maps --test-name-pattern=\"$npm_config_pattern\" --test dist-test",
19
+ "test": "node --enable-source-maps --test dist-test/**/*.test.js",
20
+ "test-some": "node --enable-source-maps --test-name-pattern=\"$npm_config_pattern\" --test dist-test/**/*.test.js",
21
21
  "watch": "tsc --build src test -w",
22
22
  "build": "tsc --build src test",
23
23
  "clean": "rm -rf dist dist-test node_modules yarn.lock package-lock.json",
@@ -35,9 +35,9 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@hapi/code": "^9.0.3",
38
- "@types/node": "22.15.17",
39
- "esbuild": "^0.25.4",
40
- "oxc-parser": "^0.68.1",
38
+ "@types/node": "24.0.7",
39
+ "esbuild": "^0.25.5",
40
+ "oxc-parser": "^0.75.0",
41
41
  "typescript": "^5.8.3"
42
42
  },
43
43
  "peerDependencies": {
@@ -45,7 +45,7 @@
45
45
  "memfs": ">=4"
46
46
  },
47
47
  "dependencies": {
48
- "diff": "^7.0.0",
48
+ "diff": "^8.0.2",
49
49
  "gubu": "^9.0.0",
50
50
  "node-diff3": "^3.1.2"
51
51
  }
@@ -13,7 +13,12 @@ const Content = cmp(function Content(props: any, children: any) {
13
13
  null != props.src ? props.src :
14
14
  'string' === typeof children ? children : ''
15
15
 
16
- src = template(src, props.ctx$.model, {
16
+ let model = {
17
+ ...props.ctx$.model,
18
+ ...(props.extra || {})
19
+ }
20
+
21
+ src = template(src, model, {
17
22
  replace: props.replace
18
23
  })
19
24
 
@@ -16,6 +16,7 @@ const FragmentShape = Gubu({
16
16
  exclude: Optional(One(Boolean, [String])) as unknown as boolean | string[],
17
17
  indent: Optional(One(Empty(String), Number)),
18
18
  replace: {} as any,
19
+ eject: Optional([One(String, RegExp)]) as unknown as any[]
19
20
  }, { name: 'Fragment' })
20
21
 
21
22
 
@@ -74,6 +75,7 @@ const Fragment = cmp(function Fragment(props: FragmentProps, children: any) {
74
75
 
75
76
  template(src, model, {
76
77
  replace,
78
+ eject: props?.eject,
77
79
  handle: (s?: string) => null == s ? null : Content(s)
78
80
  })
79
81
  })
package/src/jostraca.ts CHANGED
@@ -11,7 +11,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'
11
11
 
12
12
  import { util as JsonicUtil } from 'jsonic'
13
13
 
14
- import { Gubu, Skip } from 'gubu'
14
+ import { Gubu, Skip, One } from 'gubu'
15
15
 
16
16
  import { memfs as MemFs } from 'memfs'
17
17
 
@@ -30,7 +30,7 @@ import {
30
30
 
31
31
  import {
32
32
  each,
33
- select,
33
+ // select,
34
34
  get,
35
35
  getx,
36
36
  camelify,
@@ -49,6 +49,8 @@ import {
49
49
  } from './util/basic'
50
50
 
51
51
 
52
+ import * as PointUtil from './util/point'
53
+
52
54
  // TODO: the actual signatures
53
55
  const deep: (...args: any[]) => any = JsonicUtil.deep
54
56
  const omap: (...args: any[]) => any = JsonicUtil.omap
@@ -91,6 +93,21 @@ const DEFAULT_LOGGER = {
91
93
 
92
94
  const OptionsShape = Gubu({
93
95
  folder: Skip(String), // Base output folder for generated files. Default: `.`.
96
+
97
+ // TODO: implement
98
+ name: {
99
+ file: {
100
+ prefix: Skip(String), // Prefix for all output file names
101
+ suffix: Skip(String), // Suffix for all output file names
102
+ },
103
+ folder: {
104
+ prefix: Skip(String), // Prefix for all output folder names
105
+ suffix: Skip(String), // Prefix for all output folder names
106
+ },
107
+ // Files excluded from prefixing and suffixing
108
+ exclude: Skip(One(String, RegExp, [One(String, RegExp)]))
109
+ },
110
+
94
111
  meta: {} as any, // Provide meta data to the generation process. Default: `{}`
95
112
 
96
113
  fs: Skip(Function) as any, // File system API. Default: `node:fs`.
@@ -242,7 +259,7 @@ function Jostraca(gopts_in?: JostracaOptions | {}) {
242
259
  }
243
260
 
244
261
  if (memfs) {
245
- res.vol = memfs.vol
262
+ res.vol = () => memfs.vol
246
263
  }
247
264
 
248
265
  return res
@@ -366,8 +383,6 @@ function cmp(component: Function): Component {
366
383
  node.path.push(props.name)
367
384
  }
368
385
 
369
- // ctx$.props = () => props
370
-
371
386
  let out = component(props, children)
372
387
 
373
388
  ctx$.children = siblings
@@ -385,6 +400,7 @@ function cmp(component: Function): Component {
385
400
  // }
386
401
 
387
402
 
403
+
388
404
  export type {
389
405
  JostracaOptions,
390
406
  Component,
@@ -399,7 +415,7 @@ export {
399
415
  cmp,
400
416
 
401
417
  each,
402
- select,
418
+ // select,
403
419
  get,
404
420
  getx,
405
421
  camelify,
@@ -429,6 +445,8 @@ export {
429
445
  Line,
430
446
  Slot,
431
447
  List,
448
+
449
+ PointUtil,
432
450
  }
433
451
 
434
452
 
package/src/types.ts CHANGED
@@ -44,7 +44,7 @@ type JostracaResult = {
44
44
  conflicted: string[],
45
45
  unchanged: string[],
46
46
  }
47
- vol?: any
47
+ vol?: () => any
48
48
  }
49
49
 
50
50
 
package/src/util/basic.ts CHANGED
@@ -107,12 +107,12 @@ function each(
107
107
  }
108
108
 
109
109
 
110
-
110
+ /*
111
111
  function select(key: any, map: Record<string, Function>) {
112
112
  const fn = map && map[key]
113
113
  return fn ? fn() : undefined
114
114
  }
115
-
115
+ */
116
116
 
117
117
 
118
118
  function getx(root: any, path: string | string[]): any {
@@ -350,12 +350,41 @@ function template(
350
350
  ref?: string,
351
351
  insert?: RegExp,
352
352
  replace?: Record<string, any>,
353
+ eject?: any[]
353
354
  handle?: (s?: string) => void
354
355
  },
355
356
  ) {
356
357
 
357
358
  src = null == src ? '' : '' + src
358
359
  model = null == model ? {} : model
360
+
361
+ let eject = spec?.eject
362
+ if (null != eject) {
363
+ const ejectStart: RegExp | null = null == eject[0] ? null :
364
+ eject[0] instanceof RegExp ? eject[0] :
365
+ new RegExp('[ \t]*' + escre('' + eject[0]) + '[ \t]*\\n?')
366
+ const ejectEnd: RegExp | null = null == eject[1] ? null :
367
+ eject[1] instanceof RegExp ? eject[1] :
368
+ new RegExp('[ \t]*' + escre('' + eject[1]) + '[ \t]*\\n?')
369
+
370
+ if (null != ejectStart && null != ejectEnd) {
371
+ let startIndex = 0
372
+ let endIndex = src.length
373
+
374
+ const startMatch = src.match(ejectStart)
375
+ if (startMatch) {
376
+ startIndex = (startMatch as any).index + startMatch[0].length
377
+ }
378
+
379
+ const endMatch = src.match(ejectEnd)
380
+ if (endMatch) {
381
+ endIndex = (endMatch as any).index
382
+ }
383
+
384
+ src = src.substring(startIndex, endIndex)
385
+ }
386
+ }
387
+
359
388
  let open = null == spec?.open ? '\\$\\$' : spec.open
360
389
  let close = null == spec?.close ? '\\$\\$' : spec.close
361
390
  let ref = null == spec?.ref ? '[^$]+' : spec.ref
@@ -638,7 +667,7 @@ export {
638
667
  kebabify,
639
668
  names,
640
669
  partify,
641
- select,
670
+ // select,
642
671
  snakify,
643
672
  template,
644
673
  vmap,