@ontrails/core 0.2.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.
- package/CHANGELOG.md +849 -0
- package/README.md +190 -0
- package/package.json +36 -0
- package/src/activation-provenance.ts +116 -0
- package/src/activation-source-compatibility.ts +430 -0
- package/src/activation-source-derivation.ts +227 -0
- package/src/activation-source.ts +93 -0
- package/src/blob-ref.ts +90 -0
- package/src/branded.ts +135 -0
- package/src/collections.ts +99 -0
- package/src/compose-batch.ts +69 -0
- package/src/compose-schema.ts +36 -0
- package/src/context.ts +66 -0
- package/src/derive.ts +485 -0
- package/src/detours.ts +8 -0
- package/src/diagnostics.ts +21 -0
- package/src/draft.ts +350 -0
- package/src/entity.ts +346 -0
- package/src/error-rendering.ts +87 -0
- package/src/errors.ts +483 -0
- package/src/execute.ts +1577 -0
- package/src/fetch.ts +138 -0
- package/src/fire.ts +1172 -0
- package/src/glob.ts +81 -0
- package/src/guards.ts +37 -0
- package/src/index.ts +704 -0
- package/src/internal/fork-ctx.ts +69 -0
- package/src/layer-field-rendering.ts +193 -0
- package/src/layer.ts +81 -0
- package/src/observe.ts +361 -0
- package/src/path-scope.ts +66 -0
- package/src/path-security.ts +98 -0
- package/src/patterns/bulk.ts +16 -0
- package/src/patterns/change.ts +12 -0
- package/src/patterns/date-range.ts +12 -0
- package/src/patterns/index.ts +8 -0
- package/src/patterns/pagination.ts +22 -0
- package/src/patterns/progress.ts +13 -0
- package/src/patterns/sorting.ts +14 -0
- package/src/patterns/status.ts +11 -0
- package/src/patterns/timestamps.ts +12 -0
- package/src/permits.ts +12 -0
- package/src/queue.ts +163 -0
- package/src/redaction/index.ts +3 -0
- package/src/redaction/patterns.ts +50 -0
- package/src/redaction/redactor.ts +178 -0
- package/src/resilience.ts +234 -0
- package/src/resource-config.ts +804 -0
- package/src/resource.ts +194 -0
- package/src/result.ts +212 -0
- package/src/run.ts +76 -0
- package/src/runtime-builtins.ts +69 -0
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +326 -0
- package/src/serialization.ts +265 -0
- package/src/sha256.ts +136 -0
- package/src/signal-diagnostics.ts +633 -0
- package/src/signal-ref.ts +111 -0
- package/src/signal.ts +104 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/structured-examples.ts +248 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +101 -0
- package/src/surface-overlay.ts +694 -0
- package/src/surface-versioning.ts +42 -0
- package/src/topo.ts +835 -0
- package/src/tracing.ts +346 -0
- package/src/trail-id-glob.ts +15 -0
- package/src/trail.ts +1351 -0
- package/src/trails/derive-trail.ts +835 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +152 -0
- package/src/trails-db.ts +212 -0
- package/src/transport-error-map.ts +163 -0
- package/src/type-utils.ts +87 -0
- package/src/types.ts +300 -0
- package/src/validate-established-topo.ts +73 -0
- package/src/validate-topo.ts +725 -0
- package/src/validation.ts +330 -0
- package/src/version-marker.ts +716 -0
- package/src/version-resolution.ts +308 -0
- package/src/version-runtime.ts +120 -0
- package/src/webhook.ts +461 -0
- package/src/workspace.ts +244 -0
- package/src/zod-wrappers.ts +72 -0
package/src/glob.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface GlobConfig {
|
|
2
|
+
readonly separator: '/' | '.';
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Escape a literal string so it can be embedded safely in a RegExp source.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const pattern = new RegExp(`^${escapeRegExp('@ontrails/core')}$`);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const escapeRegExp = (value: string): string =>
|
|
14
|
+
value.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
15
|
+
|
|
16
|
+
const separatorRegExp = (separator: GlobConfig['separator']): string =>
|
|
17
|
+
escapeRegExp(separator);
|
|
18
|
+
|
|
19
|
+
export const globToRegExp = (pattern: string, config: GlobConfig): RegExp => {
|
|
20
|
+
const separator = separatorRegExp(config.separator);
|
|
21
|
+
const parts: string[] = ['^'];
|
|
22
|
+
|
|
23
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
24
|
+
const char = pattern[index];
|
|
25
|
+
const next = pattern[index + 1];
|
|
26
|
+
|
|
27
|
+
if (char === '*' && next === '*') {
|
|
28
|
+
if (pattern[index + 2] === config.separator) {
|
|
29
|
+
parts.push(`(?:.*${separator})?`);
|
|
30
|
+
index += 2;
|
|
31
|
+
} else {
|
|
32
|
+
parts.push('.*');
|
|
33
|
+
index += 1;
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (char === '*') {
|
|
39
|
+
parts.push(`[^${separator}]*`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (char === '?') {
|
|
44
|
+
parts.push(`[^${separator}]`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
parts.push(escapeRegExp(char ?? ''));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parts.push('$');
|
|
52
|
+
return new RegExp(parts.join(''));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const matchesGlob = (
|
|
56
|
+
value: string,
|
|
57
|
+
pattern: string,
|
|
58
|
+
config: GlobConfig
|
|
59
|
+
): boolean => {
|
|
60
|
+
if (value === pattern) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const terminalDoubleStar = `${config.separator}**`;
|
|
65
|
+
if (pattern.endsWith(terminalDoubleStar)) {
|
|
66
|
+
const parent = pattern.slice(0, -terminalDoubleStar.length);
|
|
67
|
+
if (value === parent) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return globToRegExp(pattern, config).test(value);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const matchesAnyGlob = (
|
|
76
|
+
value: string,
|
|
77
|
+
patterns: readonly string[] | undefined,
|
|
78
|
+
config: GlobConfig
|
|
79
|
+
): boolean =>
|
|
80
|
+
patterns !== undefined &&
|
|
81
|
+
patterns.some((pattern) => matchesGlob(value, pattern, config));
|
package/src/guards.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guards and assertion helpers for @ontrails/core.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Narrows `T | null | undefined` to `T`. */
|
|
6
|
+
export const isDefined = <T>(value?: T | null | undefined): value is T =>
|
|
7
|
+
value !== null && value !== undefined;
|
|
8
|
+
|
|
9
|
+
/** Returns true when `value` is a string with length > 0. */
|
|
10
|
+
export const isNonEmptyString = (value?: unknown): value is string =>
|
|
11
|
+
typeof value === 'string' && value.length > 0;
|
|
12
|
+
|
|
13
|
+
/** Returns true when `value` is a plain object (not an array, Date, etc.). */
|
|
14
|
+
export const isPlainObject = (
|
|
15
|
+
value: unknown
|
|
16
|
+
): value is Record<string, unknown> => {
|
|
17
|
+
if (typeof value !== 'object' || value === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const proto = Object.getPrototypeOf(value) as unknown;
|
|
21
|
+
return proto === Object.prototype || proto === null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Checks that `obj` is an object with the given key present. */
|
|
25
|
+
export const hasProperty = <K extends string>(
|
|
26
|
+
obj: unknown,
|
|
27
|
+
key: K
|
|
28
|
+
): obj is Record<K, unknown> =>
|
|
29
|
+
typeof obj === 'object' && obj !== null && key in obj;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Exhaustive switch helper. Place in the `default` branch to get a compile
|
|
33
|
+
* error when a union case is unhandled.
|
|
34
|
+
*/
|
|
35
|
+
export const assertNever = (value: never): never => {
|
|
36
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
37
|
+
};
|