@junoscript/juno 0.0.0-stage → 0.1.2
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/Modules/async.ts +81 -0
- package/Modules/juno-node-fs.ts +105 -0
- package/Modules/juno-test.jn +156 -0
- package/dist/CLI/build-juno.d.ts +5 -0
- package/dist/CLI/build-juno.js +58 -0
- package/dist/CLI/generate-juno-types.d.ts +1 -0
- package/dist/CLI/generate-juno-types.js +54 -0
- package/dist/CLI/junode.d.ts +2 -0
- package/dist/CLI/junode.js +58 -0
- package/dist/Lexer/lexer.d.ts +42 -0
- package/dist/Lexer/lexer.js +300 -0
- package/dist/Lexer/parser.d.ts +403 -0
- package/dist/Lexer/parser.js +1930 -0
- package/dist/Modules/async.d.ts +33 -0
- package/dist/Modules/async.js +76 -0
- package/dist/Modules/bytes.d.ts +15 -0
- package/dist/Modules/bytes.js +35 -0
- package/dist/Modules/index.d.ts +201 -0
- package/dist/Modules/index.js +35 -0
- package/dist/Modules/juno-node-fs.d.ts +52 -0
- package/dist/Modules/juno-node-fs.js +129 -0
- package/dist/Modules/juno-node.d.ts +74 -0
- package/dist/Modules/juno-node.js +56 -0
- package/dist/Modules/juno-test.d.ts +141 -0
- package/dist/Modules/juno-test.js +134 -0
- package/dist/Modules/juno-types.d.ts +35 -0
- package/dist/Modules/juno-types.js +2 -0
- package/dist/Modules/juno.d.ts +24 -0
- package/dist/Modules/juno.js +84 -0
- package/dist/Modules/types.d.ts +61 -0
- package/dist/Modules/types.js +95 -0
- package/dist/Runtime/interpreter.d.ts +64 -0
- package/dist/Runtime/interpreter.js +2630 -0
- package/dist/Runtime/resolve-import.d.ts +2 -0
- package/dist/Runtime/resolve-import.js +30 -0
- package/dist/vscode-junoscript/src/language.d.ts +86 -0
- package/dist/vscode-junoscript/src/language.js +4481 -0
- package/package.json +20 -4
- package/types/array.jn +158 -0
- package/types/boolean.jn +18 -0
- package/types/error.jn +28 -0
- package/types/error.ts +9 -0
- package/types/index.jn +11 -0
- package/types/iterable.jn +211 -0
- package/types/map.jn +44 -0
- package/types/map.ts +132 -0
- package/types/number.ts +52 -0
- package/types/object.jn +94 -0
- package/types/object.ts +49 -0
- package/types/queue.jn +46 -0
- package/types/random.jn +25 -0
- package/types/random.ts +1 -0
- package/types/range.jn +27 -0
- package/types/set.jn +139 -0
- package/types/set.ts +209 -0
- package/types/string.jn +33 -0
- package/types/string.ts +1 -0
- package/types/tuple.jn +11 -0
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.console = void 0;
|
|
4
|
+
exports.readEnv = readEnv;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
|
+
const pathType = {
|
|
8
|
+
kind: 'ObjectType',
|
|
9
|
+
members: [{ name: 'path', type: { kind: 'NamedType', name: 'string' }, optional: false, readonly: false, constant: false }]
|
|
10
|
+
};
|
|
11
|
+
/** Read a UTF-8 .env file without modifying process.env. */
|
|
12
|
+
function readEnv(source) {
|
|
13
|
+
return (0, node_util_1.parseEnv)((0, node_fs_1.readFileSync)(typeof source === 'string' ? source : source.path, 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
/** Node.js console module with synchronous stdin helpers. */
|
|
16
|
+
exports.console = {
|
|
17
|
+
...globalThis.console,
|
|
18
|
+
/** Arguments passed after the JunoScript file: junode <file> [args...]. */
|
|
19
|
+
get args() {
|
|
20
|
+
return process.argv.slice(3);
|
|
21
|
+
},
|
|
22
|
+
read(encoding = 'utf8') {
|
|
23
|
+
return readLine(encoding);
|
|
24
|
+
},
|
|
25
|
+
readLines(encoding = 'utf8') {
|
|
26
|
+
const input = readInput(encoding, true);
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function readInput(encoding, lines) {
|
|
31
|
+
const chunks = [];
|
|
32
|
+
const buffer = Buffer.alloc(1024);
|
|
33
|
+
let bytesRead;
|
|
34
|
+
// Read until EOF. This API is intentionally synchronous to match juno:node.
|
|
35
|
+
while ((bytesRead = (0, node_fs_1.readSync)(0, buffer, 0, buffer.length, null)) > 0) {
|
|
36
|
+
chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
|
|
37
|
+
}
|
|
38
|
+
const value = Buffer.concat(chunks).toString(encoding);
|
|
39
|
+
if (!lines)
|
|
40
|
+
return value;
|
|
41
|
+
return value.length === 0 ? [] : value.split(/\r?\n/).filter((line, index, all) => !(line === '' && index === all.length - 1));
|
|
42
|
+
}
|
|
43
|
+
function readLine(encoding) {
|
|
44
|
+
const bytes = [];
|
|
45
|
+
const buffer = Buffer.alloc(1);
|
|
46
|
+
while ((0, node_fs_1.readSync)(0, buffer, 0, 1, null) > 0) {
|
|
47
|
+
if (buffer[0] === 10)
|
|
48
|
+
break;
|
|
49
|
+
if (buffer[0] !== 13)
|
|
50
|
+
bytes.push(buffer[0]);
|
|
51
|
+
}
|
|
52
|
+
return Buffer.from(bytes).toString(encoding);
|
|
53
|
+
}
|
|
54
|
+
const junoNode = { console: exports.console, readEnv };
|
|
55
|
+
Object.defineProperty(junoNode, '__junoTypes', { value: { Path: { value: pathType, generics: [] } } });
|
|
56
|
+
exports.default = junoNode;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ModuleMocker } from 'jest-mock';
|
|
2
|
+
type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
type TestCallback = () => unknown | Promise<unknown>;
|
|
4
|
+
export type JunoExpectMatchers = {
|
|
5
|
+
that(actual: unknown): any;
|
|
6
|
+
toBe<T>(actual: T, expected: T): void;
|
|
7
|
+
toBeEqual<T>(actual: T, expected: T): void;
|
|
8
|
+
toEqual<T>(actual: T, expected: T): void;
|
|
9
|
+
toStrictEqual<T>(actual: T, expected: T): void;
|
|
10
|
+
toBeTrue(actual: boolean): void;
|
|
11
|
+
toBeTruthy(actual: unknown): void;
|
|
12
|
+
toBeFalse(actual: boolean): void;
|
|
13
|
+
toBeFalsy(actual: unknown): void;
|
|
14
|
+
toBeDefined<T>(actual: T): void;
|
|
15
|
+
toBeUndefined(actual: unknown): void;
|
|
16
|
+
toBeNull<T>(actual: T): void;
|
|
17
|
+
toBeNaN(actual: number): void;
|
|
18
|
+
toBeCloseTo(actual: number, expected: number, precision?: number): void;
|
|
19
|
+
toBeGreaterThan(actual: number, expected: number): void;
|
|
20
|
+
toBeGreaterThanOrEqual(actual: number, expected: number): void;
|
|
21
|
+
toBeLessThan(actual: number, expected: number): void;
|
|
22
|
+
toBeLessThanOrEqual(actual: number, expected: number): void;
|
|
23
|
+
toContain(actual: unknown, expected: unknown): void;
|
|
24
|
+
toContainEqual(actual: unknown, expected: unknown): void;
|
|
25
|
+
toHaveLength(actual: unknown, expected: number): void;
|
|
26
|
+
toHaveProperty(actual: object, path: string, expected?: unknown): void;
|
|
27
|
+
toMatch(actual: string, expected: string | RegExp): void;
|
|
28
|
+
toMatchObject(actual: object, expected: object): void;
|
|
29
|
+
toThrow(actual: AnyFunction, expected?: unknown): void;
|
|
30
|
+
toBeInstanceOf(actual: unknown, expected: unknown): void;
|
|
31
|
+
toHaveBeenCalled(actual: AnyFunction): void;
|
|
32
|
+
toHaveBeenCalledTimes(actual: AnyFunction, count: number): void;
|
|
33
|
+
toHaveBeenCalledWith(actual: AnyFunction, ...args: unknown[]): void;
|
|
34
|
+
toHaveBeenLastCalledWith(actual: AnyFunction, ...args: unknown[]): void;
|
|
35
|
+
toHaveBeenNthCalledWith(actual: AnyFunction, nth: number, ...args: unknown[]): void;
|
|
36
|
+
toHaveReturned(actual: AnyFunction): void;
|
|
37
|
+
toHaveReturnedTimes(actual: AnyFunction, count: number): void;
|
|
38
|
+
toHaveReturnedWith(actual: AnyFunction, value: unknown): void;
|
|
39
|
+
toHaveLastReturnedWith(actual: AnyFunction, value: unknown): void;
|
|
40
|
+
toHaveNthReturnedWith(actual: AnyFunction, nth: number, value: unknown): void;
|
|
41
|
+
any(type: unknown): unknown;
|
|
42
|
+
anything(): unknown;
|
|
43
|
+
arrayContaining(value: unknown[]): unknown;
|
|
44
|
+
arrayOf(value: unknown): unknown;
|
|
45
|
+
closeTo(value: number, precision?: number): unknown;
|
|
46
|
+
objectContaining(value: object): unknown;
|
|
47
|
+
stringContaining(value: string): unknown;
|
|
48
|
+
stringMatching(value: string | RegExp): unknown;
|
|
49
|
+
assertions(count: number): void;
|
|
50
|
+
hasAssertions(): void;
|
|
51
|
+
extend(matchers: object): void;
|
|
52
|
+
addEqualityTesters(testers: AnyFunction[]): void;
|
|
53
|
+
};
|
|
54
|
+
export type JunoExpect = JunoExpectMatchers & {
|
|
55
|
+
not: JunoExpectMatchers;
|
|
56
|
+
};
|
|
57
|
+
/** Juno-friendly two-argument matchers. `expect.not` contains their inverse. */
|
|
58
|
+
export declare const expect: JunoExpect;
|
|
59
|
+
/** Creates a real Jest mock function, including `.mock`, `mockReturnValue`, etc. */
|
|
60
|
+
export declare function Mock(implementation?: AnyFunction): ReturnType<ModuleMocker['fn']>;
|
|
61
|
+
export declare const spyOn: ModuleMocker["spyOn"];
|
|
62
|
+
export declare const replaceProperty: ModuleMocker["replaceProperty"];
|
|
63
|
+
export declare const isMockFunction: {
|
|
64
|
+
<T extends import("jest-mock").FunctionLike = import("jest-mock").UnknownFunction>(fn: import("jest-mock").MockInstance<T>): fn is import("jest-mock").MockInstance<T>;
|
|
65
|
+
<P extends Array<unknown>, R>(fn: (...args: P) => R): fn is import("jest-mock").Mock<(...args: P) => R>;
|
|
66
|
+
(fn: unknown): fn is import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
67
|
+
};
|
|
68
|
+
export declare const clearAllMocks: () => void;
|
|
69
|
+
export declare const resetAllMocks: () => void;
|
|
70
|
+
export declare const restoreAllMocks: () => void;
|
|
71
|
+
export declare const useFakeTimers: (fakeTimersConfig?: {
|
|
72
|
+
advanceTimers?: boolean | number;
|
|
73
|
+
doNotFake?: Array<"Date" | "hrtime" | "nextTick" | "performance" | "queueMicrotask" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "Temporal">;
|
|
74
|
+
now?: number | Date | {
|
|
75
|
+
epochMilliseconds: number;
|
|
76
|
+
};
|
|
77
|
+
timerLimit?: number;
|
|
78
|
+
legacyFakeTimers?: false;
|
|
79
|
+
}) => void;
|
|
80
|
+
export declare const useRealTimers: () => void;
|
|
81
|
+
export declare const clearAllTimers: () => void;
|
|
82
|
+
export declare const runAllTimers: () => void;
|
|
83
|
+
export declare const runAllTimersAsync: () => Promise<void>;
|
|
84
|
+
export declare const runOnlyPendingTimers: () => void;
|
|
85
|
+
export declare const advanceTimersByTime: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => void;
|
|
86
|
+
export declare const advanceTimersByTimeAsync: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => Promise<void>;
|
|
87
|
+
export declare const advanceTimersToNextTimer: (steps?: number) => void;
|
|
88
|
+
export declare const setSystemTime: (now?: number | Date | import("@sinonjs/fake-timers").TemporalTimelike) => void;
|
|
89
|
+
export declare const getTimerCount: () => number;
|
|
90
|
+
/** A lightweight in-process Jest-style suite for executable `.jn` files. */
|
|
91
|
+
export declare function describe(name: string, body: TestCallback): unknown;
|
|
92
|
+
export declare function beforeEach(callback: TestCallback): void;
|
|
93
|
+
export declare function afterEach(callback: TestCallback): void;
|
|
94
|
+
export declare function test(name: string, body: TestCallback): unknown;
|
|
95
|
+
export declare namespace test {
|
|
96
|
+
var only: typeof test;
|
|
97
|
+
var skip: (_name: string, _body: TestCallback) => void;
|
|
98
|
+
}
|
|
99
|
+
export declare const it: typeof test;
|
|
100
|
+
declare const _default: {
|
|
101
|
+
expect: JunoExpect;
|
|
102
|
+
Mock: typeof Mock;
|
|
103
|
+
spyOn: {
|
|
104
|
+
<T extends object, K extends import("jest-mock").PropertyLikeKeys<T>, V extends Required<T>[K], A extends "get" | "set">(object: T, methodKey: K, accessType: A): A extends "get" ? import("jest-mock").SpiedGetter<V> : A extends "set" ? import("jest-mock").SpiedSetter<V> : never;
|
|
105
|
+
<T extends object, K extends import("jest-mock").ConstructorLikeKeys<T> | import("jest-mock").MethodLikeKeys<T>, V extends Required<T>[K]>(object: T, methodKey: K): V extends import("jest-mock").ClassLike | import("jest-mock").FunctionLike ? import("jest-mock").Spied<V> : never;
|
|
106
|
+
};
|
|
107
|
+
replaceProperty: <T extends object, K extends keyof T>(object: T, propertyKey: K, value: T[K]) => import("jest-mock").Replaced<T[K]>;
|
|
108
|
+
isMockFunction: {
|
|
109
|
+
<T extends import("jest-mock").FunctionLike = import("jest-mock").UnknownFunction>(fn: import("jest-mock").MockInstance<T>): fn is import("jest-mock").MockInstance<T>;
|
|
110
|
+
<P extends Array<unknown>, R>(fn: (...args: P) => R): fn is import("jest-mock").Mock<(...args: P) => R>;
|
|
111
|
+
(fn: unknown): fn is import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
112
|
+
};
|
|
113
|
+
clearAllMocks: () => void;
|
|
114
|
+
resetAllMocks: () => void;
|
|
115
|
+
restoreAllMocks: () => void;
|
|
116
|
+
describe: typeof describe;
|
|
117
|
+
test: typeof test;
|
|
118
|
+
it: typeof test;
|
|
119
|
+
beforeEach: typeof beforeEach;
|
|
120
|
+
afterEach: typeof afterEach;
|
|
121
|
+
useFakeTimers: (fakeTimersConfig?: {
|
|
122
|
+
advanceTimers?: boolean | number;
|
|
123
|
+
doNotFake?: Array<"Date" | "hrtime" | "nextTick" | "performance" | "queueMicrotask" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "Temporal">;
|
|
124
|
+
now?: number | Date | {
|
|
125
|
+
epochMilliseconds: number;
|
|
126
|
+
};
|
|
127
|
+
timerLimit?: number;
|
|
128
|
+
legacyFakeTimers?: false;
|
|
129
|
+
}) => void;
|
|
130
|
+
useRealTimers: () => void;
|
|
131
|
+
clearAllTimers: () => void;
|
|
132
|
+
runAllTimers: () => void;
|
|
133
|
+
runAllTimersAsync: () => Promise<void>;
|
|
134
|
+
runOnlyPendingTimers: () => void;
|
|
135
|
+
advanceTimersByTime: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => void;
|
|
136
|
+
advanceTimersByTimeAsync: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => Promise<void>;
|
|
137
|
+
advanceTimersToNextTimer: (steps?: number) => void;
|
|
138
|
+
setSystemTime: (now?: number | Date | import("@sinonjs/fake-timers").TemporalTimelike) => void;
|
|
139
|
+
getTimerCount: () => number;
|
|
140
|
+
};
|
|
141
|
+
export default _default;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.it = exports.getTimerCount = exports.setSystemTime = exports.advanceTimersToNextTimer = exports.advanceTimersByTimeAsync = exports.advanceTimersByTime = exports.runOnlyPendingTimers = exports.runAllTimersAsync = exports.runAllTimers = exports.clearAllTimers = exports.useRealTimers = exports.useFakeTimers = exports.restoreAllMocks = exports.resetAllMocks = exports.clearAllMocks = exports.isMockFunction = exports.replaceProperty = exports.spyOn = exports.expect = void 0;
|
|
7
|
+
exports.Mock = Mock;
|
|
8
|
+
exports.describe = describe;
|
|
9
|
+
exports.beforeEach = beforeEach;
|
|
10
|
+
exports.afterEach = afterEach;
|
|
11
|
+
exports.test = test;
|
|
12
|
+
const expect_1 = __importDefault(require("expect"));
|
|
13
|
+
const fake_timers_1 = require("@jest/fake-timers");
|
|
14
|
+
const jest_mock_1 = require("jest-mock");
|
|
15
|
+
const moduleMocker = new jest_mock_1.ModuleMocker(globalThis);
|
|
16
|
+
const timers = new fake_timers_1.ModernFakeTimers({
|
|
17
|
+
global: globalThis,
|
|
18
|
+
config: { fakeTimers: { enableGlobally: false } }
|
|
19
|
+
});
|
|
20
|
+
/** Jest's regular `expect(value)` entry point. */
|
|
21
|
+
const that = expect_1.default;
|
|
22
|
+
function assertion(jestName, actual, expected, inverse) {
|
|
23
|
+
const matchers = inverse ? (0, expect_1.default)(actual).not : (0, expect_1.default)(actual);
|
|
24
|
+
const candidate = matchers[jestName];
|
|
25
|
+
if (typeof candidate !== 'function')
|
|
26
|
+
throw new TypeError(`Unknown Jest matcher '${jestName}'`);
|
|
27
|
+
candidate.apply(matchers, expected);
|
|
28
|
+
}
|
|
29
|
+
const matcherNames = {
|
|
30
|
+
toBe: 'toBe', toBeEqual: 'toEqual', toEqual: 'toEqual', toStrictEqual: 'toStrictEqual',
|
|
31
|
+
toBeTrue: 'toBeTruthy', toBeTruthy: 'toBeTruthy', toBeFalse: 'toBeFalsy', toBeFalsy: 'toBeFalsy',
|
|
32
|
+
toBeDefined: 'toBeDefined', toBeUndefined: 'toBeUndefined', toBeNull: 'toBeNull', toBeNaN: 'toBeNaN',
|
|
33
|
+
toBeCloseTo: 'toBeCloseTo', toBeGreaterThan: 'toBeGreaterThan', toBeGreaterThanOrEqual: 'toBeGreaterThanOrEqual',
|
|
34
|
+
toBeLessThan: 'toBeLessThan', toBeLessThanOrEqual: 'toBeLessThanOrEqual', toContain: 'toContain',
|
|
35
|
+
toContainEqual: 'toContainEqual', toHaveLength: 'toHaveLength', toHaveProperty: 'toHaveProperty',
|
|
36
|
+
toMatch: 'toMatch', toMatchObject: 'toMatchObject', toThrow: 'toThrow', toBeInstanceOf: 'toBeInstanceOf',
|
|
37
|
+
toHaveBeenCalled: 'toHaveBeenCalled', toHaveBeenCalledTimes: 'toHaveBeenCalledTimes',
|
|
38
|
+
toHaveBeenCalledWith: 'toHaveBeenCalledWith', toHaveBeenLastCalledWith: 'toHaveBeenLastCalledWith',
|
|
39
|
+
toHaveBeenNthCalledWith: 'toHaveBeenNthCalledWith', toHaveReturned: 'toHaveReturned',
|
|
40
|
+
toHaveReturnedTimes: 'toHaveReturnedTimes', toHaveReturnedWith: 'toHaveReturnedWith',
|
|
41
|
+
toHaveLastReturnedWith: 'toHaveLastReturnedWith', toHaveNthReturnedWith: 'toHaveNthReturnedWith'
|
|
42
|
+
};
|
|
43
|
+
function createExpect(inverse) {
|
|
44
|
+
const api = {
|
|
45
|
+
that, any: expect_1.default.any, anything: expect_1.default.anything,
|
|
46
|
+
arrayContaining: expect_1.default.arrayContaining, arrayOf: expect_1.default.arrayOf,
|
|
47
|
+
closeTo: expect_1.default.closeTo, objectContaining: expect_1.default.objectContaining,
|
|
48
|
+
stringContaining: expect_1.default.stringContaining, stringMatching: expect_1.default.stringMatching,
|
|
49
|
+
assertions: expect_1.default.assertions, hasAssertions: expect_1.default.hasAssertions,
|
|
50
|
+
extend: expect_1.default.extend, addEqualityTesters: expect_1.default.addEqualityTesters
|
|
51
|
+
};
|
|
52
|
+
for (const [name, jestName] of Object.entries(matcherNames)) {
|
|
53
|
+
api[name] = (actual, ...expected) => {
|
|
54
|
+
if (name === 'toBeDefined')
|
|
55
|
+
return assertion('toBeNull', actual, [], !inverse);
|
|
56
|
+
if (name === 'toBeTrue')
|
|
57
|
+
return assertion('toBe', actual, [true], inverse);
|
|
58
|
+
if (name === 'toBeFalse')
|
|
59
|
+
return assertion('toBe', actual, [false], inverse);
|
|
60
|
+
return assertion(jestName, actual, expected, inverse);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return api;
|
|
64
|
+
}
|
|
65
|
+
/** Juno-friendly two-argument matchers. `expect.not` contains their inverse. */
|
|
66
|
+
exports.expect = createExpect(false);
|
|
67
|
+
exports.expect.not = createExpect(true);
|
|
68
|
+
/** Creates a real Jest mock function, including `.mock`, `mockReturnValue`, etc. */
|
|
69
|
+
function Mock(implementation) {
|
|
70
|
+
return moduleMocker.fn(implementation);
|
|
71
|
+
}
|
|
72
|
+
exports.spyOn = moduleMocker.spyOn.bind(moduleMocker);
|
|
73
|
+
exports.replaceProperty = moduleMocker.replaceProperty.bind(moduleMocker);
|
|
74
|
+
exports.isMockFunction = moduleMocker.isMockFunction.bind(moduleMocker);
|
|
75
|
+
exports.clearAllMocks = moduleMocker.clearAllMocks.bind(moduleMocker);
|
|
76
|
+
exports.resetAllMocks = moduleMocker.resetAllMocks.bind(moduleMocker);
|
|
77
|
+
exports.restoreAllMocks = moduleMocker.restoreAllMocks.bind(moduleMocker);
|
|
78
|
+
exports.useFakeTimers = timers.useFakeTimers.bind(timers);
|
|
79
|
+
exports.useRealTimers = timers.useRealTimers.bind(timers);
|
|
80
|
+
exports.clearAllTimers = timers.clearAllTimers.bind(timers);
|
|
81
|
+
exports.runAllTimers = timers.runAllTimers.bind(timers);
|
|
82
|
+
exports.runAllTimersAsync = timers.runAllTimersAsync.bind(timers);
|
|
83
|
+
exports.runOnlyPendingTimers = timers.runOnlyPendingTimers.bind(timers);
|
|
84
|
+
exports.advanceTimersByTime = timers.advanceTimersByTime.bind(timers);
|
|
85
|
+
exports.advanceTimersByTimeAsync = timers.advanceTimersByTimeAsync.bind(timers);
|
|
86
|
+
exports.advanceTimersToNextTimer = timers.advanceTimersToNextTimer.bind(timers);
|
|
87
|
+
exports.setSystemTime = timers.setSystemTime.bind(timers);
|
|
88
|
+
exports.getTimerCount = timers.getTimerCount.bind(timers);
|
|
89
|
+
let suiteNames = [];
|
|
90
|
+
let beforeEachCallbacks = [];
|
|
91
|
+
let afterEachCallbacks = [];
|
|
92
|
+
/** A lightweight in-process Jest-style suite for executable `.jn` files. */
|
|
93
|
+
function describe(name, body) {
|
|
94
|
+
suiteNames.push(name);
|
|
95
|
+
try {
|
|
96
|
+
return body();
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
suiteNames.pop();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function beforeEach(callback) { beforeEachCallbacks.push(callback); }
|
|
103
|
+
function afterEach(callback) { afterEachCallbacks.push(callback); }
|
|
104
|
+
function test(name, body) {
|
|
105
|
+
const fullName = [...suiteNames, name].join(' > ');
|
|
106
|
+
const execute = async () => {
|
|
107
|
+
try {
|
|
108
|
+
for (const callback of beforeEachCallbacks)
|
|
109
|
+
await callback();
|
|
110
|
+
await body();
|
|
111
|
+
console.log(`\u2713 ${fullName}`);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error(`\u2717 ${fullName}`);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
for (const callback of afterEachCallbacks)
|
|
119
|
+
await callback();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
return execute();
|
|
123
|
+
}
|
|
124
|
+
test.only = test;
|
|
125
|
+
test.skip = (_name, _body) => undefined;
|
|
126
|
+
exports.it = test;
|
|
127
|
+
exports.default = {
|
|
128
|
+
expect: exports.expect, Mock, spyOn: exports.spyOn, replaceProperty: exports.replaceProperty, isMockFunction: exports.isMockFunction,
|
|
129
|
+
clearAllMocks: exports.clearAllMocks, resetAllMocks: exports.resetAllMocks, restoreAllMocks: exports.restoreAllMocks,
|
|
130
|
+
describe, test, it: exports.it, beforeEach, afterEach,
|
|
131
|
+
useFakeTimers: exports.useFakeTimers, useRealTimers: exports.useRealTimers, clearAllTimers: exports.clearAllTimers, runAllTimers: exports.runAllTimers, runAllTimersAsync: exports.runAllTimersAsync,
|
|
132
|
+
runOnlyPendingTimers: exports.runOnlyPendingTimers, advanceTimersByTime: exports.advanceTimersByTime, advanceTimersByTimeAsync: exports.advanceTimersByTimeAsync,
|
|
133
|
+
advanceTimersToNextTimer: exports.advanceTimersToNextTimer, setSystemTime: exports.setSystemTime, getTimerCount: exports.getTimerCount
|
|
134
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Generated from types/iterable.jn. Edit the JunoScript source instead. */
|
|
2
|
+
export type Iterable<T> = (({
|
|
3
|
+
iterator(): () => ({
|
|
4
|
+
value: T;
|
|
5
|
+
} | null);
|
|
6
|
+
} | {
|
|
7
|
+
toArray(): Array<T>;
|
|
8
|
+
}) & {
|
|
9
|
+
toArray(): Array<T>;
|
|
10
|
+
get length(): number;
|
|
11
|
+
at(index: number): (T | null);
|
|
12
|
+
concat(other: Array<T>): Array<T>;
|
|
13
|
+
every(callback: (arg0: T) => boolean): boolean;
|
|
14
|
+
filter(callback: (arg0: T) => boolean): Array<T>;
|
|
15
|
+
flat(): Array<unknown>;
|
|
16
|
+
find(callback: (arg0: T) => boolean): (T | null);
|
|
17
|
+
findLast(callback: (arg0: T) => boolean): (T | null);
|
|
18
|
+
flatMap(callback: (arg0: T) => Array<T>): Array<T>;
|
|
19
|
+
forEach(callback: (arg0: T) => unknown): void;
|
|
20
|
+
includes(value: T): boolean;
|
|
21
|
+
indexOf(value: T): number;
|
|
22
|
+
lastIndexOf(value: T): number;
|
|
23
|
+
join(separator?: string): string;
|
|
24
|
+
map(callback: (arg0: T) => unknown): Array<unknown>;
|
|
25
|
+
reduce(callback: (arg0: T, arg1: T) => T, initial: T): T;
|
|
26
|
+
reduceRight(callback: (arg0: T, arg1: T) => T, initial: T): T;
|
|
27
|
+
slice(start?: number, end?: number): Array<T>;
|
|
28
|
+
toReversed(): Array<T>;
|
|
29
|
+
toSorted(): Array<T>;
|
|
30
|
+
toLocaleString(): string;
|
|
31
|
+
toString(): string;
|
|
32
|
+
toSpliced(start: number, deleteCount: number, items?: Array<T>): Array<T>;
|
|
33
|
+
with(index: number, value: T): Array<T>;
|
|
34
|
+
some(callback: (arg0: T) => boolean): boolean;
|
|
35
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Standard JunoScript console module; mirrors the JavaScript/TypeScript console. */
|
|
2
|
+
import { types } from './types';
|
|
3
|
+
import type { Iterable } from './juno-types';
|
|
4
|
+
import { BufferConstructor, Uint8ArrayConstructor } from './bytes';
|
|
5
|
+
export { BufferConstructor as Buffer, Uint8ArrayConstructor as Uint8Array };
|
|
6
|
+
export type { Encoding } from './bytes';
|
|
7
|
+
export declare const console: Console;
|
|
8
|
+
export { types };
|
|
9
|
+
export type { Iterable } from './juno-types';
|
|
10
|
+
export type Range = Iterable<number> & {
|
|
11
|
+
readonly start: number;
|
|
12
|
+
readonly end: number;
|
|
13
|
+
readonly step: number;
|
|
14
|
+
};
|
|
15
|
+
/** TypeScript entry point matching the JunoScript Range constructor. */
|
|
16
|
+
export declare function Range(start: number, end?: number, step?: number): Range;
|
|
17
|
+
/** TypeScript-compatible error shape for values thrown or returned by Juno code. */
|
|
18
|
+
export type Error = {
|
|
19
|
+
name: string;
|
|
20
|
+
message: string;
|
|
21
|
+
stack?: string;
|
|
22
|
+
};
|
|
23
|
+
declare const juno: Record<string, any>;
|
|
24
|
+
export default juno;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.types = exports.console = exports.Uint8Array = exports.Buffer = void 0;
|
|
4
|
+
exports.Range = Range;
|
|
5
|
+
/** Standard JunoScript console module; mirrors the JavaScript/TypeScript console. */
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
Object.defineProperty(exports, "types", { enumerable: true, get: function () { return types_1.types; } });
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const lexer_1 = require("../Lexer/lexer");
|
|
11
|
+
const parser_1 = require("../Lexer/parser");
|
|
12
|
+
const bytes_1 = require("./bytes");
|
|
13
|
+
Object.defineProperty(exports, "Buffer", { enumerable: true, get: function () { return bytes_1.BufferConstructor; } });
|
|
14
|
+
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return bytes_1.Uint8ArrayConstructor; } });
|
|
15
|
+
exports.console = globalThis.console;
|
|
16
|
+
/** TypeScript entry point matching the JunoScript Range constructor. */
|
|
17
|
+
function Range(start, end, step = 1) {
|
|
18
|
+
if (end === undefined)
|
|
19
|
+
[start, end] = [0, start];
|
|
20
|
+
const first = start;
|
|
21
|
+
const last = end;
|
|
22
|
+
const values = () => {
|
|
23
|
+
const result = [];
|
|
24
|
+
if (step > 0)
|
|
25
|
+
for (let value = first; value < last; value += step)
|
|
26
|
+
result.push(value);
|
|
27
|
+
else if (step < 0)
|
|
28
|
+
for (let value = first; value > last; value += step)
|
|
29
|
+
result.push(value);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
start: first,
|
|
34
|
+
end: last,
|
|
35
|
+
step,
|
|
36
|
+
iterator: () => {
|
|
37
|
+
const items = values();
|
|
38
|
+
let index = 0;
|
|
39
|
+
return () => index < items.length ? { value: items[index++] } : null;
|
|
40
|
+
},
|
|
41
|
+
toArray: values
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const JunoMath = Object.create(Math);
|
|
45
|
+
Object.defineProperties(JunoMath, {
|
|
46
|
+
NaN: { value: Number.NaN, enumerable: true },
|
|
47
|
+
Infinity: { value: Number.POSITIVE_INFINITY, enumerable: true }
|
|
48
|
+
});
|
|
49
|
+
const juno = {
|
|
50
|
+
console: exports.console,
|
|
51
|
+
Buffer: bytes_1.BufferConstructor,
|
|
52
|
+
Uint8Array: bytes_1.Uint8ArrayConstructor,
|
|
53
|
+
Math: JunoMath,
|
|
54
|
+
types: types_1.types,
|
|
55
|
+
Error,
|
|
56
|
+
Range
|
|
57
|
+
};
|
|
58
|
+
// Parse the JunoScript declaration so runtime JN imports use the same type AST.
|
|
59
|
+
const iterableSource = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, '../../types/iterable.jn'), 'utf8');
|
|
60
|
+
const iterableDeclaration = new parser_1.Parser((0, lexer_1.Lexer)(iterableSource).tokenize()).parse().find(statement => statement.kind === 'Export' && statement.declaration.kind === 'TypeDeclaration' && statement.declaration.name === 'Iterable');
|
|
61
|
+
if (!iterableDeclaration || iterableDeclaration.kind !== 'Export' || iterableDeclaration.declaration.kind !== 'TypeDeclaration') {
|
|
62
|
+
throw new Error("types/iterable.jn must export type 'Iterable'");
|
|
63
|
+
}
|
|
64
|
+
const iterableType = iterableDeclaration.declaration.value;
|
|
65
|
+
const junoTypes = {
|
|
66
|
+
Error: { value: { kind: 'ObjectType', members: [
|
|
67
|
+
{ name: 'name', type: { kind: 'NamedType', name: 'string' }, optional: false, readonly: false, constant: false },
|
|
68
|
+
{ name: 'message', type: { kind: 'NamedType', name: 'string' }, optional: false, readonly: false, constant: false },
|
|
69
|
+
{ name: 'stack', type: { kind: 'NamedType', name: 'string' }, optional: true, readonly: false, constant: false }
|
|
70
|
+
] }, generics: [] },
|
|
71
|
+
Iterable: { value: iterableType, generics: iterableDeclaration.declaration.generics }
|
|
72
|
+
};
|
|
73
|
+
for (const [name, alias] of Object.entries(junoTypes))
|
|
74
|
+
juno[name] = {
|
|
75
|
+
__junoTypeConstructor: true,
|
|
76
|
+
typeName: name,
|
|
77
|
+
typeNode: alias.value,
|
|
78
|
+
generics: alias.generics
|
|
79
|
+
};
|
|
80
|
+
Object.defineProperty(juno, '__junoTypes', {
|
|
81
|
+
value: { ...junoTypes, Encoding: { value: { kind: 'UnionType', types: bytes_1.encodings.map(value => ({ kind: 'LiteralType', value })) }, generics: [] } },
|
|
82
|
+
enumerable: false
|
|
83
|
+
});
|
|
84
|
+
exports.default = juno;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** TypeScript utility types re-exported as a module for project consumers. */
|
|
2
|
+
import type { TypeNode } from '../Lexer/parser';
|
|
3
|
+
export type Partial<T> = {
|
|
4
|
+
[P in keyof T]?: T[P];
|
|
5
|
+
};
|
|
6
|
+
export type Required<T> = {
|
|
7
|
+
[P in keyof T]-?: T[P];
|
|
8
|
+
};
|
|
9
|
+
export type Readonly<T> = {
|
|
10
|
+
readonly [P in keyof T]: T[P];
|
|
11
|
+
};
|
|
12
|
+
export type KeyOf<T extends object> = keyof T;
|
|
13
|
+
export type Pick<T, K extends keyof T> = {
|
|
14
|
+
[P in K]: T[P];
|
|
15
|
+
};
|
|
16
|
+
export type Record<K extends keyof any, T> = {
|
|
17
|
+
[P in K]: T;
|
|
18
|
+
};
|
|
19
|
+
export type Exclude<T, U> = T extends U ? never : T;
|
|
20
|
+
export type Extract<T, U> = T extends U ? T : never;
|
|
21
|
+
export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
22
|
+
export type NonNullable<T> = Exclude<T, null | undefined>;
|
|
23
|
+
export type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
24
|
+
export type ConstructorParameters<T extends abstract new (...args: any[]) => any> = T extends abstract new (...args: infer P) => any ? P : never;
|
|
25
|
+
export type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
|
|
26
|
+
export type InstanceType<T extends abstract new (...args: any[]) => any> = T extends abstract new (...args: any[]) => infer R ? R : any;
|
|
27
|
+
export type ThisParameterType<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown;
|
|
28
|
+
export type OmitThisParameter<T> = unknown extends ThisParameterType<T> ? T : T extends (this: any, ...args: infer A) => infer R ? (...args: A) => R : T;
|
|
29
|
+
export type ThisType<T> = {};
|
|
30
|
+
export type Awaited<T> = T extends null | undefined ? T : T extends object & {
|
|
31
|
+
then(onfulfilled: infer F, ...args: any[]): any;
|
|
32
|
+
} ? F extends (value: infer V, ...args: any[]) => any ? Awaited<V> : never : T;
|
|
33
|
+
type RuntimeTypeInput = {
|
|
34
|
+
__junoTypeConstructor?: true;
|
|
35
|
+
__junoTypeDescriptor?: true;
|
|
36
|
+
typeNode?: TypeNode;
|
|
37
|
+
};
|
|
38
|
+
export declare const Partial: (input: unknown) => RuntimeTypeInput;
|
|
39
|
+
export declare const Required: (input: unknown) => RuntimeTypeInput;
|
|
40
|
+
export declare const Readonly: (input: unknown) => RuntimeTypeInput;
|
|
41
|
+
export declare const KeyOf: (input: unknown) => RuntimeTypeInput;
|
|
42
|
+
export declare const Exclude: (input: unknown, excluded: unknown) => RuntimeTypeInput;
|
|
43
|
+
export declare const Pick: (input: unknown, keys: unknown) => RuntimeTypeInput;
|
|
44
|
+
export declare const Omit: (input: unknown, keys: unknown) => RuntimeTypeInput;
|
|
45
|
+
export declare const Items: () => (string | number)[];
|
|
46
|
+
export declare const Keys: () => (string | number)[];
|
|
47
|
+
declare function createDate(value?: string | number | Date): Date;
|
|
48
|
+
export { createDate as Date };
|
|
49
|
+
export declare const types: {
|
|
50
|
+
Partial: (input: unknown) => RuntimeTypeInput;
|
|
51
|
+
Required: (input: unknown) => RuntimeTypeInput;
|
|
52
|
+
Readonly: (input: unknown) => RuntimeTypeInput;
|
|
53
|
+
Pick: (input: unknown, keys: unknown) => RuntimeTypeInput;
|
|
54
|
+
Omit: (input: unknown, keys: unknown) => RuntimeTypeInput;
|
|
55
|
+
KeyOf: (input: unknown) => RuntimeTypeInput;
|
|
56
|
+
Exclude: (input: unknown, excluded: unknown) => RuntimeTypeInput;
|
|
57
|
+
Items: () => (string | number)[];
|
|
58
|
+
Keys: () => (string | number)[];
|
|
59
|
+
Date: typeof createDate;
|
|
60
|
+
};
|
|
61
|
+
export default types;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.types = exports.Keys = exports.Items = exports.Omit = exports.Pick = exports.Exclude = exports.KeyOf = exports.Readonly = exports.Required = exports.Partial = void 0;
|
|
4
|
+
exports.Date = createDate;
|
|
5
|
+
function typeNodeOf(input) {
|
|
6
|
+
const node = input?.typeNode;
|
|
7
|
+
if (node && typeof node === 'object' && 'kind' in node)
|
|
8
|
+
return node;
|
|
9
|
+
throw new TypeError('Expected a Juno type declaration or a runtime type descriptor');
|
|
10
|
+
}
|
|
11
|
+
function descriptor(typeNode) {
|
|
12
|
+
return { __junoTypeDescriptor: true, typeNode };
|
|
13
|
+
}
|
|
14
|
+
function transformMembers(typeNode, transform) {
|
|
15
|
+
if (typeNode.kind === 'ObjectType')
|
|
16
|
+
return { ...typeNode, members: transform(typeNode.members) };
|
|
17
|
+
if (typeNode.kind === 'UnionType' || typeNode.kind === 'IntersectionType') {
|
|
18
|
+
return { ...typeNode, types: typeNode.types.map(part => transformMembers(part, transform)) };
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError(`Utility type requires an object type; received ${typeNode.kind}`);
|
|
21
|
+
}
|
|
22
|
+
function keyLiteral(name) {
|
|
23
|
+
const numeric = Number(name);
|
|
24
|
+
return { kind: 'LiteralType', value: name !== '' && Number.isFinite(numeric) && String(numeric) === name ? numeric : name };
|
|
25
|
+
}
|
|
26
|
+
function keyType(typeNode) {
|
|
27
|
+
if (typeNode.kind === 'ArrayType' || typeNode.kind === 'GenericType' && (typeNode.name === 'Array' || typeNode.name === 'ReadonlyArray')) {
|
|
28
|
+
const names = ['length', 'indices', 'has', 'pick', 'omit', 'deepClone', 'deepFreeze', 'toDeepFreezed', 'at', 'concat', 'copy', 'copyWithin', 'entries', 'enumerate', 'every', 'fill', 'filter', 'find', 'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'iterator', 'join', 'lastIndexOf', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toArray', 'toReversed', 'toSorted', 'toSpliced', 'toString', 'unshift', 'with'];
|
|
29
|
+
return { kind: 'UnionType', types: [{ kind: 'NamedType', name: 'number' }, ...names.map(name => ({ kind: 'LiteralType', value: name }))] };
|
|
30
|
+
}
|
|
31
|
+
if (typeNode.kind === 'ObjectType') {
|
|
32
|
+
const keys = typeNode.members.flatMap(member => member.indexType ? [member.indexType] : [keyLiteral(member.name)]);
|
|
33
|
+
return keys.length === 1 ? keys[0] : { kind: 'UnionType', types: keys };
|
|
34
|
+
}
|
|
35
|
+
if (typeNode.kind === 'UnionType' || typeNode.kind === 'IntersectionType') {
|
|
36
|
+
const keys = typeNode.types.map(keyType);
|
|
37
|
+
return keys.length === 1 ? keys[0] : { kind: 'UnionType', types: keys };
|
|
38
|
+
}
|
|
39
|
+
throw new TypeError(`KeyOf requires an object or array type; received ${typeNode.kind}`);
|
|
40
|
+
}
|
|
41
|
+
function excludeType(source, excluded) {
|
|
42
|
+
const excludedParts = excluded.kind === 'UnionType' ? excluded.types : [excluded];
|
|
43
|
+
const parts = source.kind === 'UnionType' ? source.types : [source];
|
|
44
|
+
const remaining = parts.filter(part => !excludedParts.some(item => JSON.stringify(item) === JSON.stringify(part)));
|
|
45
|
+
return remaining.length === 1 ? remaining[0] : remaining.length ? { kind: 'UnionType', types: remaining } : { kind: 'NamedType', name: 'never' };
|
|
46
|
+
}
|
|
47
|
+
function keysFrom(value) {
|
|
48
|
+
if (Array.isArray(value) && value.every(key => typeof key === 'string'))
|
|
49
|
+
return new Set(value);
|
|
50
|
+
const node = value?.typeNode;
|
|
51
|
+
if (node?.kind === 'LiteralType' && typeof node.value === 'string')
|
|
52
|
+
return new Set([node.value]);
|
|
53
|
+
if (node?.kind === 'UnionType') {
|
|
54
|
+
const keys = new Set();
|
|
55
|
+
for (const part of node.types) {
|
|
56
|
+
if (part.kind !== 'LiteralType' || typeof part.value !== 'string')
|
|
57
|
+
throw new TypeError('Utility type keys must be string literal types');
|
|
58
|
+
keys.add(part.value);
|
|
59
|
+
}
|
|
60
|
+
return keys;
|
|
61
|
+
}
|
|
62
|
+
throw new TypeError('Utility type keys must be string literals or an array of strings');
|
|
63
|
+
}
|
|
64
|
+
const Partial = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, optional: true }))));
|
|
65
|
+
exports.Partial = Partial;
|
|
66
|
+
const Required = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, optional: false }))));
|
|
67
|
+
exports.Required = Required;
|
|
68
|
+
const Readonly = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, readonly: true }))));
|
|
69
|
+
exports.Readonly = Readonly;
|
|
70
|
+
const KeyOf = (input) => descriptor(keyType(typeNodeOf(input)));
|
|
71
|
+
exports.KeyOf = KeyOf;
|
|
72
|
+
const Exclude = (input, excluded) => descriptor(excludeType(typeNodeOf(input), typeNodeOf(excluded)));
|
|
73
|
+
exports.Exclude = Exclude;
|
|
74
|
+
const Pick = (input, keys) => {
|
|
75
|
+
const selected = keysFrom(keys);
|
|
76
|
+
return descriptor(transformMembers(typeNodeOf(input), members => members.filter(member => selected.has(member.name))));
|
|
77
|
+
};
|
|
78
|
+
exports.Pick = Pick;
|
|
79
|
+
const Omit = (input, keys) => {
|
|
80
|
+
const removed = keysFrom(keys);
|
|
81
|
+
return descriptor(transformMembers(typeNodeOf(input), members => members.filter(member => !removed.has(member.name))));
|
|
82
|
+
};
|
|
83
|
+
exports.Omit = Omit;
|
|
84
|
+
// The interpreter materializes Items<T>() from its compile-time literal type argument.
|
|
85
|
+
const Items = () => [];
|
|
86
|
+
exports.Items = Items;
|
|
87
|
+
const Keys = () => [];
|
|
88
|
+
exports.Keys = Keys;
|
|
89
|
+
function createDate(value) {
|
|
90
|
+
if (value === undefined)
|
|
91
|
+
return new Date();
|
|
92
|
+
return new Date(value instanceof Date ? value.getTime() : value);
|
|
93
|
+
}
|
|
94
|
+
exports.types = { Partial: exports.Partial, Required: exports.Required, Readonly: exports.Readonly, Pick: exports.Pick, Omit: exports.Omit, KeyOf: exports.KeyOf, Exclude: exports.Exclude, Items: exports.Items, Keys: exports.Keys, Date: createDate };
|
|
95
|
+
exports.default = exports.types;
|