@reactive-contracts/compiler 0.1.0-beta
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/LICENSE +21 -0
- package/dist/bin/rcontracts.js +7 -0
- package/dist/index.cjs +474 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.cli.js +1094 -0
- package/dist/index.d.cts +53 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +469 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/gitignore.template +24 -0
- package/dist/templates/rcontracts.config.template.ts +33 -0
- package/dist/templates/sample-contract.template.ts +40 -0
- package/package.json +64 -0
- package/templates/gitignore.template +24 -0
- package/templates/rcontracts.config.template.ts +33 -0
- package/templates/sample-contract.template.ts +40 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Generated files
|
|
2
|
+
generated/
|
|
3
|
+
|
|
4
|
+
# Dependencies
|
|
5
|
+
node_modules/
|
|
6
|
+
|
|
7
|
+
# Build outputs
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.tsbuildinfo
|
|
11
|
+
|
|
12
|
+
# Environment
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/
|
|
18
|
+
.idea/
|
|
19
|
+
*.swp
|
|
20
|
+
*.swo
|
|
21
|
+
|
|
22
|
+
# OS
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineConfig } from '@reactive-contracts/compiler';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
// Pattern to find contract files
|
|
5
|
+
contracts: './contracts/**/*.contract.ts',
|
|
6
|
+
|
|
7
|
+
// Where to generate code
|
|
8
|
+
output: {
|
|
9
|
+
frontend: './generated/frontend',
|
|
10
|
+
backend: './generated/backend',
|
|
11
|
+
runtime: './generated/runtime',
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
// Validation rules
|
|
15
|
+
validation: {
|
|
16
|
+
strictLatency: false, // Alpha: warn only, don't fail
|
|
17
|
+
requireIntent: true, // All contracts should have an intent
|
|
18
|
+
maxComplexity: 10, // Limit derivation complexity
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// Optimization flags (alpha: disabled)
|
|
22
|
+
optimization: {
|
|
23
|
+
bundleSplitting: false,
|
|
24
|
+
treeShaking: false,
|
|
25
|
+
precompute: [],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
// External integrations (not yet implemented)
|
|
29
|
+
integrations: {
|
|
30
|
+
// prisma: './prisma/schema.prisma',
|
|
31
|
+
// graphql: './schema.graphql',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { contract, derive, max, daysAgo } from '@reactive-contracts/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sample Contract
|
|
5
|
+
*
|
|
6
|
+
* This is an example contract to help you get started.
|
|
7
|
+
* You can modify or delete this file.
|
|
8
|
+
*/
|
|
9
|
+
export const SampleContract = contract({
|
|
10
|
+
name: 'Sample',
|
|
11
|
+
intent: 'Demonstrate basic contract structure',
|
|
12
|
+
|
|
13
|
+
shape: {
|
|
14
|
+
data: {
|
|
15
|
+
id: 'string',
|
|
16
|
+
name: 'string',
|
|
17
|
+
createdAt: 'Date',
|
|
18
|
+
},
|
|
19
|
+
metadata: {
|
|
20
|
+
count: 'number',
|
|
21
|
+
status: derive(
|
|
22
|
+
(ctx: { data: { createdAt: Date } }) =>
|
|
23
|
+
ctx.data.createdAt > daysAgo(30) ? 'recent' : 'old',
|
|
24
|
+
{
|
|
25
|
+
dependencies: ['data.createdAt'],
|
|
26
|
+
preferredLayer: 'client',
|
|
27
|
+
}
|
|
28
|
+
),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
constraints: {
|
|
33
|
+
latency: max('100ms', { fallback: 'cachedVersion' }),
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
reactivity: {
|
|
37
|
+
static: ['data.id', 'data.name', 'data.createdAt'],
|
|
38
|
+
polling: [{ field: 'metadata.count', interval: '30s' }],
|
|
39
|
+
},
|
|
40
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reactive-contracts/compiler",
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
|
+
"description": "Build-time compiler and validator for Reactive Contracts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rcontracts": "./dist/bin/rcontracts.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"templates",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"commander": "^14.0.2",
|
|
23
|
+
"fs-extra": "^11.3.3",
|
|
24
|
+
"glob": "^13.0.0",
|
|
25
|
+
"ora": "^9.0.0",
|
|
26
|
+
"picocolors": "^1.1.1",
|
|
27
|
+
"tsx": "^4.21.0",
|
|
28
|
+
"zod": "^4.3.5",
|
|
29
|
+
"@reactive-contracts/core": "0.1.0-beta"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/fs-extra": "^11.0.4",
|
|
33
|
+
"@types/node": "^25.0.3",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vitest": "^4.0.16"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"contracts",
|
|
40
|
+
"api",
|
|
41
|
+
"typescript",
|
|
42
|
+
"compiler",
|
|
43
|
+
"validation"
|
|
44
|
+
],
|
|
45
|
+
"author": "Reactive Contracts Contributors",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"homepage": "https://github.com/creativoma/reactive-contracts",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/creativoma/reactive-contracts.git",
|
|
51
|
+
"directory": "packages/compiler"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup && pnpm run copy-templates && pnpm run copy-bin",
|
|
58
|
+
"copy-templates": "mkdir -p dist/templates && cp -r templates/* dist/templates/",
|
|
59
|
+
"copy-bin": "mkdir -p dist/bin && cp bin/rcontracts.js dist/bin/",
|
|
60
|
+
"dev": "tsup --watch",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"clean": "rm -rf dist"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Generated files
|
|
2
|
+
generated/
|
|
3
|
+
|
|
4
|
+
# Dependencies
|
|
5
|
+
node_modules/
|
|
6
|
+
|
|
7
|
+
# Build outputs
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.tsbuildinfo
|
|
11
|
+
|
|
12
|
+
# Environment
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/
|
|
18
|
+
.idea/
|
|
19
|
+
*.swp
|
|
20
|
+
*.swo
|
|
21
|
+
|
|
22
|
+
# OS
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineConfig } from '@reactive-contracts/compiler';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
// Pattern to find contract files
|
|
5
|
+
contracts: './contracts/**/*.contract.ts',
|
|
6
|
+
|
|
7
|
+
// Where to generate code
|
|
8
|
+
output: {
|
|
9
|
+
frontend: './generated/frontend',
|
|
10
|
+
backend: './generated/backend',
|
|
11
|
+
runtime: './generated/runtime',
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
// Validation rules
|
|
15
|
+
validation: {
|
|
16
|
+
strictLatency: false, // Alpha: warn only, don't fail
|
|
17
|
+
requireIntent: true, // All contracts should have an intent
|
|
18
|
+
maxComplexity: 10, // Limit derivation complexity
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// Optimization flags (alpha: disabled)
|
|
22
|
+
optimization: {
|
|
23
|
+
bundleSplitting: false,
|
|
24
|
+
treeShaking: false,
|
|
25
|
+
precompute: [],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
// External integrations (not yet implemented)
|
|
29
|
+
integrations: {
|
|
30
|
+
// prisma: './prisma/schema.prisma',
|
|
31
|
+
// graphql: './schema.graphql',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { contract, derive, max, daysAgo } from '@reactive-contracts/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sample Contract
|
|
5
|
+
*
|
|
6
|
+
* This is an example contract to help you get started.
|
|
7
|
+
* You can modify or delete this file.
|
|
8
|
+
*/
|
|
9
|
+
export const SampleContract = contract({
|
|
10
|
+
name: 'Sample',
|
|
11
|
+
intent: 'Demonstrate basic contract structure',
|
|
12
|
+
|
|
13
|
+
shape: {
|
|
14
|
+
data: {
|
|
15
|
+
id: 'string',
|
|
16
|
+
name: 'string',
|
|
17
|
+
createdAt: 'Date',
|
|
18
|
+
},
|
|
19
|
+
metadata: {
|
|
20
|
+
count: 'number',
|
|
21
|
+
status: derive(
|
|
22
|
+
(ctx: { data: { createdAt: Date } }) =>
|
|
23
|
+
ctx.data.createdAt > daysAgo(30) ? 'recent' : 'old',
|
|
24
|
+
{
|
|
25
|
+
dependencies: ['data.createdAt'],
|
|
26
|
+
preferredLayer: 'client',
|
|
27
|
+
}
|
|
28
|
+
),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
constraints: {
|
|
33
|
+
latency: max('100ms', { fallback: 'cachedVersion' }),
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
reactivity: {
|
|
37
|
+
static: ['data.id', 'data.name', 'data.createdAt'],
|
|
38
|
+
polling: [{ field: 'metadata.count', interval: '30s' }],
|
|
39
|
+
},
|
|
40
|
+
});
|