@intrig/plugin-react 0.0.1 → 0.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.
Files changed (54) hide show
  1. package/package.json +6 -3
  2. package/.swcrc +0 -29
  3. package/eslint.config.mjs +0 -19
  4. package/project.json +0 -29
  5. package/rollup.config.cjs +0 -54
  6. package/rollup.config.mjs +0 -33
  7. package/src/index.ts +0 -2
  8. package/src/lib/code-generator.ts +0 -79
  9. package/src/lib/get-endpoint-documentation.ts +0 -35
  10. package/src/lib/get-schema-documentation.ts +0 -11
  11. package/src/lib/internal-types.ts +0 -15
  12. package/src/lib/plugin-react.ts +0 -22
  13. package/src/lib/templates/context.template.ts +0 -74
  14. package/src/lib/templates/docs/__snapshots__/async-hook.spec.ts.snap +0 -889
  15. package/src/lib/templates/docs/__snapshots__/download-hook.spec.ts.snap +0 -1445
  16. package/src/lib/templates/docs/__snapshots__/react-hook.spec.ts.snap +0 -1371
  17. package/src/lib/templates/docs/__snapshots__/sse-hook.spec.ts.snap +0 -2008
  18. package/src/lib/templates/docs/async-hook.spec.ts +0 -92
  19. package/src/lib/templates/docs/async-hook.ts +0 -226
  20. package/src/lib/templates/docs/download-hook.spec.ts +0 -182
  21. package/src/lib/templates/docs/download-hook.ts +0 -170
  22. package/src/lib/templates/docs/react-hook.spec.ts +0 -97
  23. package/src/lib/templates/docs/react-hook.ts +0 -323
  24. package/src/lib/templates/docs/schema.ts +0 -105
  25. package/src/lib/templates/docs/sse-hook.spec.ts +0 -207
  26. package/src/lib/templates/docs/sse-hook.ts +0 -221
  27. package/src/lib/templates/extra.template.ts +0 -198
  28. package/src/lib/templates/index.template.ts +0 -14
  29. package/src/lib/templates/intrigMiddleware.template.ts +0 -21
  30. package/src/lib/templates/logger.template.ts +0 -67
  31. package/src/lib/templates/media-type-utils.template.ts +0 -191
  32. package/src/lib/templates/network-state.template.ts +0 -702
  33. package/src/lib/templates/packageJson.template.ts +0 -63
  34. package/src/lib/templates/provider/__tests__/provider-templates.spec.ts +0 -209
  35. package/src/lib/templates/provider/axios-config.template.ts +0 -49
  36. package/src/lib/templates/provider/hooks.template.ts +0 -240
  37. package/src/lib/templates/provider/interfaces.template.ts +0 -72
  38. package/src/lib/templates/provider/intrig-provider-stub.template.ts +0 -73
  39. package/src/lib/templates/provider/intrig-provider.template.ts +0 -185
  40. package/src/lib/templates/provider/main.template.ts +0 -48
  41. package/src/lib/templates/provider/reducer.template.ts +0 -50
  42. package/src/lib/templates/provider/status-trap.template.ts +0 -80
  43. package/src/lib/templates/provider.template.ts +0 -698
  44. package/src/lib/templates/source/controller/method/asyncFunctionHook.template.ts +0 -196
  45. package/src/lib/templates/source/controller/method/clientIndex.template.ts +0 -38
  46. package/src/lib/templates/source/controller/method/download.template.ts +0 -256
  47. package/src/lib/templates/source/controller/method/params.template.ts +0 -31
  48. package/src/lib/templates/source/controller/method/requestHook.template.ts +0 -220
  49. package/src/lib/templates/source/type/typeTemplate.ts +0 -257
  50. package/src/lib/templates/swcrc.template.ts +0 -25
  51. package/src/lib/templates/tsconfig.template.ts +0 -37
  52. package/src/lib/templates/type-utils.template.ts +0 -28
  53. package/tsconfig.json +0 -13
  54. package/tsconfig.lib.json +0 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intrig/plugin-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -8,7 +8,6 @@
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
10
  ".": {
11
- "development": "./src/index.ts",
12
11
  "types": "./dist/index.d.ts",
13
12
  "import": "./dist/index.js",
14
13
  "require": "./dist/index.cjs",
@@ -16,9 +15,13 @@
16
15
  }
17
16
  },
18
17
  "dependencies": {
19
- "@intrig/plugin-sdk": "^0.0.1",
18
+ "@intrig/plugin-sdk": "^0.0.2-0",
20
19
  "@swc/helpers": "~0.5.11"
21
20
  },
21
+ "files": [
22
+ "dist",
23
+ "package.json"
24
+ ],
22
25
  "publishConfig": {
23
26
  "access": "public"
24
27
  }
package/.swcrc DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$",
27
- ".*.js$"
28
- ]
29
- }
package/eslint.config.mjs DELETED
@@ -1,19 +0,0 @@
1
- import baseConfig from '../../eslint.base.config.mjs';
2
-
3
- export default [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
12
- },
13
- ],
14
- },
15
- languageOptions: {
16
- parser: await import('jsonc-eslint-parser'),
17
- },
18
- },
19
- ];
package/project.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "@intrig/plugin-react",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "plugins/react/src",
5
- "projectType": "library",
6
- "tags": ["Intrig", "react", "generator"],
7
- "targets": {
8
- "build": {
9
- "executor": "@nx/rollup:rollup",
10
- "outputs": ["{options.outputPath}"],
11
- "options": {
12
- "outputPath": "dist/plugins/react",
13
- "main": "plugins/react/src/index.ts",
14
- "tsConfig": "plugins/react/tsconfig.lib.json",
15
- "compiler": "swc",
16
- "format": ["esm", "cjs"],
17
- "outputFileName": "index.js",
18
- "assets": [
19
- {
20
- "input": "plugins/react",
21
- "glob": "package.json",
22
- "output": "."
23
- }
24
- ],
25
- "rollupConfig": "plugins/react/rollup.config.cjs"
26
- }
27
- }
28
- }
29
- }
package/rollup.config.cjs DELETED
@@ -1,54 +0,0 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
3
-
4
- function getPkgJson(pkgDir) {
5
- const pkgPath = path.join(pkgDir, 'package.json');
6
- if (fs.existsSync(pkgPath)) {
7
- return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
8
- }
9
- return {};
10
- }
11
-
12
- const pkg = getPkgJson(__dirname);
13
- const rootPkg = getPkgJson(path.resolve(__dirname, '../..'));
14
-
15
- const deps = new Set([
16
- ...Object.keys(pkg.dependencies || {}),
17
- ...Object.keys(pkg.peerDependencies || {}),
18
- ...Object.keys(rootPkg.dependencies || {}),
19
- ...Object.keys(rootPkg.peerDependencies || {}),
20
- ]);
21
-
22
- function external(id) {
23
- if (id.startsWith('.') || path.isAbsolute(id)) return false; // bundle local files
24
- // Treat any bare module specifier or node_modules import as external
25
- if (id.includes('node_modules')) return true;
26
- const [scopeOrName, maybeName] = id.split('/');
27
- const name = scopeOrName && scopeOrName.startsWith('@') && maybeName ? `${scopeOrName}/${maybeName}` : scopeOrName;
28
- return deps.has(name);
29
- }
30
-
31
- module.exports = (config) => {
32
- const newConfig = { ...config };
33
- if (Array.isArray(newConfig.output)) {
34
- newConfig.output = newConfig.output.map((o) => ({
35
- ...o,
36
- // Emit all JS files under a nested 'dist' directory inside the outputPath
37
- entryFileNames: o.format === 'cjs' ? 'dist/index.cjs' : 'dist/index.js',
38
- chunkFileNames: o.format === 'cjs' ? 'dist/[name].cjs' : 'dist/[name].js',
39
- assetFileNames: 'dist/[name][extname]',
40
- exports: o.format === 'cjs' ? 'named' : undefined
41
- }));
42
- } else if (newConfig.output) {
43
- newConfig.output = {
44
- ...newConfig.output,
45
- // Emit all JS files under a nested 'dist' directory inside the outputPath
46
- entryFileNames: newConfig.output.format === 'cjs' ? 'dist/index.cjs' : 'dist/index.js',
47
- chunkFileNames: newConfig.output.format === 'cjs' ? 'dist/[name].cjs' : 'dist/[name].js',
48
- assetFileNames: 'dist/[name][extname]',
49
- exports: newConfig.output.format === 'cjs' ? 'named' : undefined
50
- };
51
- }
52
- newConfig.external = external;
53
- return newConfig;
54
- };
package/rollup.config.mjs DELETED
@@ -1,33 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- function getPkgJson(pkgDir) {
5
- const pkgPath = path.join(pkgDir, 'package.json');
6
- if (fs.existsSync(pkgPath)) {
7
- return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
8
- }
9
- return {};
10
- }
11
-
12
- const pkg = getPkgJson(new URL('.', import.meta.url).pathname);
13
- const rootPkg = getPkgJson(path.resolve(__dirname, '../..'));
14
-
15
- const deps = new Set([
16
- ...Object.keys(pkg.dependencies || {}),
17
- ...Object.keys(pkg.peerDependencies || {}),
18
- ...Object.keys(rootPkg.dependencies || {}),
19
- ...Object.keys(rootPkg.peerDependencies || {}),
20
- ]);
21
-
22
- function external(id) {
23
- if (id.startsWith('.') || path.isAbsolute(id)) return false; // bundle local files
24
- // Treat any bare module specifier or node_modules import as external
25
- if (id.includes('node_modules')) return true;
26
- const [scopeOrName, maybeName] = id.split('/');
27
- const name = scopeOrName?.startsWith('@') && maybeName ? `${scopeOrName}/${maybeName}` : scopeOrName;
28
- return deps.has(name);
29
- }
30
-
31
- export default () => ({
32
- external,
33
- });
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default } from './lib/plugin-react.js';
2
- export { createPlugin } from './lib/plugin-react.js';
@@ -1,79 +0,0 @@
1
- import { GeneratorContext, StatsCounter } from "@intrig/plugin-sdk";
2
- import {InternalGeneratorContext} from "./internal-types.js";
3
- import { packageJsonTemplate } from "./templates/packageJson.template.js";
4
- import { indexTemplate } from "./templates/index.template.js";
5
- import { networkStateTemplate } from "./templates/network-state.template.js";
6
- import { contextTemplate } from "./templates/context.template.js";
7
- import { reactLoggerTemplate } from "./templates/logger.template.js";
8
- import { reactExtraTemplate } from "./templates/extra.template.js";
9
- import { reactMediaTypeUtilsTemplate } from "./templates/media-type-utils.template.js";
10
- import { typeUtilsTemplate } from "./templates/type-utils.template.js";
11
- import { reactTsConfigTemplate } from "./templates/tsconfig.template.js";
12
- import { reactSwcrcTemplate } from "./templates/swcrc.template.js";
13
- import { intrigMiddlewareTemplate } from "./templates/intrigMiddleware.template.js";
14
-
15
- // Provider modular templates
16
- import { providerMainTemplate } from "./templates/provider/main.template.js";
17
- import { providerHooksTemplate } from "./templates/provider/hooks.template.js";
18
- import { providerInterfacesTemplate } from "./templates/provider/interfaces.template.js";
19
- import { providerReducerTemplate } from "./templates/provider/reducer.template.js";
20
- import { providerAxiosConfigTemplate } from "./templates/provider/axios-config.template.js";
21
- import { reactIntrigProviderTemplate } from "./templates/provider/intrig-provider.template.js";
22
- import { reactIntrigProviderStubTemplate } from "./templates/provider/intrig-provider-stub.template.js";
23
- import { reactStatusTrapTemplate } from "./templates/provider/status-trap.template.js";
24
- import {requestHookTemplate} from "./templates/source/controller/method/requestHook.template.js";
25
- import {paramsTemplate} from "./templates/source/controller/method/params.template.js";
26
- import {asyncFunctionHookTemplate} from "./templates/source/controller/method/asyncFunctionHook.template.js";
27
- import {clientIndexTemplate} from "./templates/source/controller/method/clientIndex.template.js";
28
- import {downloadHookTemplate} from "./templates/source/controller/method/download.template.js";
29
- import {typeTemplate} from "./templates/source/type/typeTemplate.js";
30
-
31
- export async function generateCode(ctx: GeneratorContext): Promise<StatsCounter[]> {
32
- // Root/project files
33
- await ctx.dump(packageJsonTemplate());
34
- await ctx.dump(reactTsConfigTemplate());
35
- await ctx.dump(reactSwcrcTemplate());
36
-
37
- // Top-level src files
38
- await ctx.dump(indexTemplate());
39
- await ctx.dump(networkStateTemplate());
40
- await ctx.dump(contextTemplate(ctx.sources));
41
- await ctx.dump(reactLoggerTemplate());
42
- await ctx.dump(reactExtraTemplate());
43
- await ctx.dump(reactMediaTypeUtilsTemplate());
44
- await ctx.dump(typeUtilsTemplate());
45
- await ctx.dump(intrigMiddlewareTemplate());
46
-
47
- // Provider modular files (placed under src)
48
- await ctx.dump(providerMainTemplate(ctx.sources));
49
- await ctx.dump(providerHooksTemplate());
50
- await ctx.dump(providerInterfacesTemplate(ctx.sources));
51
- await ctx.dump(providerReducerTemplate());
52
- await ctx.dump(providerAxiosConfigTemplate(ctx.sources));
53
- await ctx.dump(reactIntrigProviderTemplate(ctx.sources));
54
- await ctx.dump(reactIntrigProviderStubTemplate(ctx.sources));
55
- await ctx.dump(reactStatusTrapTemplate(ctx.sources));
56
-
57
- const potentiallyConflictingDescriptors = ctx.restDescriptors
58
- .sort((a, b) => (a.data.contentType === "application/json" ? -1 : 0) - (b.data.contentType === "application/json" ? -1 : 0))
59
- .filter((descriptor, index, array) => array.findIndex(other => other.data.operationId === descriptor.data.operationId) !== index)
60
- .map(descriptor => descriptor.id);
61
-
62
- const internalGeneratorContext = new InternalGeneratorContext(potentiallyConflictingDescriptors);
63
-
64
- for (const restDescriptor of ctx.restDescriptors) {
65
- await ctx.dump(requestHookTemplate(restDescriptor, internalGeneratorContext));
66
- await ctx.dump(paramsTemplate(restDescriptor, internalGeneratorContext));
67
- await ctx.dump(asyncFunctionHookTemplate(restDescriptor, internalGeneratorContext));
68
- if (restDescriptor.data.isDownloadable) {
69
- await ctx.dump(downloadHookTemplate(restDescriptor, internalGeneratorContext))
70
- }
71
- await ctx.dump(clientIndexTemplate([restDescriptor], internalGeneratorContext))
72
- }
73
-
74
- for (const schemaDescriptor of ctx.schemaDescriptors) {
75
- ctx.dump(typeTemplate(schemaDescriptor))
76
- }
77
-
78
- return internalGeneratorContext.getCounters()
79
- }
@@ -1,35 +0,0 @@
1
- import {ResourceDescriptor, RestData, Tab} from "@intrig/plugin-sdk";
2
- import {reactSseHookDocs} from "./templates/docs/sse-hook.js";
3
- import {reactHookDocs} from "./templates/docs/react-hook.js";
4
- import {reactAsyncFunctionHookDocs} from "./templates/docs/async-hook.js";
5
- import {reactDownloadHookDocs} from "./templates/docs/download-hook.js";
6
-
7
- export async function getEndpointDocumentation(result: ResourceDescriptor<RestData>): Promise<Tab[]> {
8
-
9
- const tabs: Tab[] = []
10
- if (result.data.responseType === 'text/event-stream') {
11
- tabs.push({
12
- name: 'SSE Hook',
13
- content: (await reactSseHookDocs(result)).content
14
- })
15
- } else {
16
- tabs.push({
17
- name: 'Stateful Hook',
18
- content: (await reactHookDocs(result)).content
19
- })
20
- }
21
-
22
- tabs.push({
23
- name: 'Stateless Hook',
24
- content: (await reactAsyncFunctionHookDocs(result)).content
25
- })
26
-
27
- if (result.data.isDownloadable) {
28
- tabs.push({
29
- name: 'Download Hook',
30
- content: (await reactDownloadHookDocs(result)).content
31
- })
32
- }
33
-
34
- return tabs
35
- }
@@ -1,11 +0,0 @@
1
- import {ResourceDescriptor, Schema, Tab} from "@intrig/plugin-sdk";
2
- import {schemaJsonSchemaDoc, schemaTypescriptDoc, schemaZodSchemaDoc} from "./templates/docs/schema.js";
3
-
4
- export async function getSchemaDocumentation(result: ResourceDescriptor<Schema>): Promise<Tab[]> {
5
- const tabs: Tab[] = []
6
- tabs.push({ name: 'Typescript Type', content: (await schemaTypescriptDoc(result)).content })
7
- tabs.push({ name: 'JSON Schema', content: (await schemaJsonSchemaDoc(result)).content })
8
- tabs.push({ name: 'Zod Schema', content: (await schemaZodSchemaDoc(result)).content })
9
-
10
- return tabs
11
- }
@@ -1,15 +0,0 @@
1
- import { StatsCounter } from "@intrig/plugin-sdk";
2
-
3
- export class InternalGeneratorContext {
4
- private codeGenerationBreakdown: Record<string, StatsCounter> = {};
5
- constructor(public readonly potentiallyConflictingDescriptors: string[]) {}
6
-
7
- getCounter(sourceId: string) {
8
- this.codeGenerationBreakdown[sourceId] = this.codeGenerationBreakdown[sourceId] || new StatsCounter(sourceId);
9
- return this.codeGenerationBreakdown[sourceId];
10
- }
11
-
12
- getCounters() {
13
- return [...Object.values(this.codeGenerationBreakdown)];
14
- }
15
- }
@@ -1,22 +0,0 @@
1
- import {IntrigGeneratorPlugin} from '@intrig/plugin-sdk'
2
- import {generateCode} from "./code-generator.js";
3
- import {getSchemaDocumentation} from "./get-schema-documentation.js";
4
- import {getEndpointDocumentation} from "./get-endpoint-documentation.js";
5
-
6
- function createPlugin(): IntrigGeneratorPlugin {
7
- return {
8
- meta() {
9
- return {
10
- name: 'intrig-binding',
11
- version: '0.0.1',
12
- compat: '^0.0.15'
13
- }
14
- },
15
- generate: generateCode,
16
- getSchemaDocumentation,
17
- getEndpointDocumentation
18
- }
19
- }
20
-
21
- export { createPlugin };
22
- export default createPlugin;
@@ -1,74 +0,0 @@
1
- import {IntrigSourceConfig, typescript} from "@intrig/plugin-sdk";
2
- import * as path from 'path'
3
-
4
- export function contextTemplate(apisToSync: IntrigSourceConfig[]) {
5
- const ts = typescript(path.resolve("src", "intrig-context.ts"))
6
-
7
- const configType = `{
8
- defaults?: DefaultConfigs,
9
- ${apisToSync.map(a => `${a.id}?: DefaultConfigs`).join(",\n ")}
10
- }`
11
-
12
- return ts`
13
- import { NetworkAction, NetworkState } from '@intrig/react/network-state';
14
- import { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
15
- import { ZodSchema, ZodType, ZodTypeDef } from 'zod';
16
- import { createContext, useContext, Dispatch } from 'react';
17
- import { DefaultConfigs } from './interfaces';
18
-
19
- type GlobalState = Record<string, NetworkState>;
20
-
21
- interface RequestType<T = any> extends AxiosRequestConfig {
22
- originalData?: T; // Keeps track of the original data type.
23
- key: string;
24
- source: string
25
- }
26
-
27
- export type SchemaOf<T> = ZodType<T, ZodTypeDef, any>;
28
-
29
- /**
30
- * Defines the ContextType interface for managing global state, dispatching actions,
31
- * and holding a collection of Axios instances.
32
- *
33
- * @interface ContextType
34
- * @property {GlobalState} state - The global state of the application.
35
- * @property {Dispatch<NetworkAction<unknown>>} dispatch - The dispatch function to send network actions.
36
- * @property {Record<string, AxiosInstance>} axios - A record of Axios instances for making HTTP requests.
37
- */
38
- export interface ContextType {
39
- state: GlobalState;
40
- filteredState: GlobalState;
41
- dispatch: Dispatch<NetworkAction<unknown>>;
42
- configs: ${configType};
43
- execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: SchemaOf<T> | undefined, errorSchema: SchemaOf<T> | undefined) => Promise<void>;
44
- }
45
-
46
- /**
47
- * Context object created using \`createContext\` function. Provides a way to share state, dispatch functions,
48
- * and axios instance across components without having to pass props down manually at every level.
49
- *
50
- * @type {ContextType}
51
- */
52
- const Context = createContext<ContextType>({
53
- state: {},
54
- filteredState: {},
55
- dispatch() {
56
- //intentionally left blank
57
- },
58
- configs: {},
59
- async execute() {
60
- //intentionally left blank
61
- },
62
- });
63
-
64
- export function useIntrigContext() {
65
- return useContext(Context);
66
- }
67
-
68
- export {
69
- Context,
70
- GlobalState,
71
- RequestType,
72
- }
73
- `
74
- }