@intrig/plugin-react 0.0.2-5 ā 0.0.2-7
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/dist/index.cjs +54 -39
- package/dist/index.js +54 -39
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var pluginSdk = require('@intrig/plugin-sdk');
|
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var fsx = require('fs-extra');
|
|
8
8
|
var mimeType = require('mime-types');
|
|
9
|
+
var chalk = require('chalk');
|
|
9
10
|
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
11
12
|
var n = Object.create(null);
|
|
@@ -1417,24 +1418,6 @@ function reactSwcrcTemplate() {
|
|
|
1417
1418
|
`;
|
|
1418
1419
|
}
|
|
1419
1420
|
|
|
1420
|
-
function intrigMiddlewareTemplate() {
|
|
1421
|
-
const ts = pluginSdk.typescript(path__namespace.resolve('src', 'intrig-middleware.ts'));
|
|
1422
|
-
return ts`
|
|
1423
|
-
import axios from 'axios';
|
|
1424
|
-
import { requestInterceptor } from 'intrig-hook';
|
|
1425
|
-
|
|
1426
|
-
export function getAxiosInstance(key: string) {
|
|
1427
|
-
let axiosInstance = axios.create({
|
|
1428
|
-
baseURL: process.env[${"`${key.toUpperCase()}_API_URL`"}],
|
|
1429
|
-
});
|
|
1430
|
-
|
|
1431
|
-
axiosInstance.interceptors.request.use(requestInterceptor);
|
|
1432
|
-
|
|
1433
|
-
return axiosInstance;
|
|
1434
|
-
}
|
|
1435
|
-
`;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
1421
|
function flushSyncUtilTemplate(ctx) {
|
|
1439
1422
|
var _packageJson_dependencies, _packageJson_devDependencies, _packageJson_peerDependencies;
|
|
1440
1423
|
const ts = pluginSdk.typescript(path__namespace.resolve('src', 'utils', 'flush-sync.ts'));
|
|
@@ -1555,6 +1538,7 @@ function providerHooksTemplate() {
|
|
|
1555
1538
|
useMemo,
|
|
1556
1539
|
useState,
|
|
1557
1540
|
useRef,
|
|
1541
|
+
useEffect,
|
|
1558
1542
|
} from 'react';
|
|
1559
1543
|
import {
|
|
1560
1544
|
ErrorState,
|
|
@@ -1598,6 +1582,16 @@ export function useNetworkState<T>({
|
|
|
1598
1582
|
const context = useContext(Context);
|
|
1599
1583
|
|
|
1600
1584
|
const [abortController, setAbortController] = useState<AbortController>();
|
|
1585
|
+
|
|
1586
|
+
const contextRef = useRef(context);
|
|
1587
|
+
const schemaRef = useRef(schema);
|
|
1588
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
1589
|
+
|
|
1590
|
+
useEffect(() => {
|
|
1591
|
+
contextRef.current = context;
|
|
1592
|
+
schemaRef.current = schema;
|
|
1593
|
+
errorSchemaRef.current = errorSchema;
|
|
1594
|
+
});
|
|
1601
1595
|
|
|
1602
1596
|
const networkState = useMemo(() => {
|
|
1603
1597
|
logger.info(${"`Updating status ${key} ${operation} ${source}`"});
|
|
@@ -1606,7 +1600,7 @@ export function useNetworkState<T>({
|
|
|
1606
1600
|
(context.state?.[${"`${source}:${operation}:${key}`"}] as NetworkState<T>) ??
|
|
1607
1601
|
init()
|
|
1608
1602
|
);
|
|
1609
|
-
}, [
|
|
1603
|
+
}, [context.state, key, operation, source]);
|
|
1610
1604
|
|
|
1611
1605
|
const dispatch = useCallback(
|
|
1612
1606
|
(state: NetworkState<T>) => {
|
|
@@ -1654,30 +1648,30 @@ export function useNetworkState<T>({
|
|
|
1654
1648
|
signal: abortController.signal,
|
|
1655
1649
|
};
|
|
1656
1650
|
|
|
1657
|
-
await
|
|
1651
|
+
await contextRef.current.execute(
|
|
1658
1652
|
requestConfig,
|
|
1659
1653
|
dispatch,
|
|
1660
|
-
|
|
1661
|
-
|
|
1654
|
+
schemaRef.current,
|
|
1655
|
+
errorSchemaRef.current as any,
|
|
1662
1656
|
);
|
|
1663
1657
|
},
|
|
1664
|
-
[
|
|
1658
|
+
[dispatch, key, operation, source],
|
|
1665
1659
|
);
|
|
1666
1660
|
|
|
1667
1661
|
const deboundedExecute = useMemo(
|
|
1668
|
-
() => debounce(execute, debounceDelay
|
|
1669
|
-
[execute],
|
|
1662
|
+
() => debounce(execute, debounceDelay),
|
|
1663
|
+
[execute, debounceDelay],
|
|
1670
1664
|
);
|
|
1671
1665
|
|
|
1672
1666
|
const clear = useCallback(() => {
|
|
1673
1667
|
logger.info(${"`Clearing request ${key} ${operation} ${source}`"});
|
|
1674
1668
|
dispatch(init());
|
|
1675
|
-
setAbortController((
|
|
1669
|
+
setAbortController((prev) => {
|
|
1676
1670
|
logger.info(${"`Aborting request ${key} ${operation} ${source}`"});
|
|
1677
|
-
|
|
1671
|
+
prev?.abort();
|
|
1678
1672
|
return undefined;
|
|
1679
1673
|
});
|
|
1680
|
-
}, [dispatch,
|
|
1674
|
+
}, [dispatch, key, operation, source]);
|
|
1681
1675
|
|
|
1682
1676
|
return [networkState, deboundedExecute, clear, dispatch];
|
|
1683
1677
|
}
|
|
@@ -1694,6 +1688,14 @@ export function useTransitionCall<T>({
|
|
|
1694
1688
|
}): [(request: RequestType) => Promise<T>, () => void] {
|
|
1695
1689
|
const ctx = useContext(Context);
|
|
1696
1690
|
const controller = useRef<AbortController | undefined>(undefined);
|
|
1691
|
+
|
|
1692
|
+
const schemaRef = useRef(schema);
|
|
1693
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
1694
|
+
|
|
1695
|
+
useEffect(() => {
|
|
1696
|
+
schemaRef.current = schema;
|
|
1697
|
+
errorSchemaRef.current = errorSchema;
|
|
1698
|
+
});
|
|
1697
1699
|
|
|
1698
1700
|
const call = useCallback(
|
|
1699
1701
|
async (request: RequestType) => {
|
|
@@ -1711,12 +1713,12 @@ export function useTransitionCall<T>({
|
|
|
1711
1713
|
reject(state.error);
|
|
1712
1714
|
}
|
|
1713
1715
|
},
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
+
schemaRef.current,
|
|
1717
|
+
errorSchemaRef.current,
|
|
1716
1718
|
);
|
|
1717
1719
|
});
|
|
1718
1720
|
},
|
|
1719
|
-
[ctx
|
|
1721
|
+
[ctx],
|
|
1720
1722
|
);
|
|
1721
1723
|
|
|
1722
1724
|
const abort = useCallback(() => {
|
|
@@ -3193,7 +3195,6 @@ async function generateCode(ctx) {
|
|
|
3193
3195
|
await ctx.dump(reactExtraTemplate());
|
|
3194
3196
|
await ctx.dump(reactMediaTypeUtilsTemplate());
|
|
3195
3197
|
await ctx.dump(typeUtilsTemplate());
|
|
3196
|
-
await ctx.dump(intrigMiddlewareTemplate());
|
|
3197
3198
|
await ctx.dump(flushSyncUtilTemplate(ctx));
|
|
3198
3199
|
// Provider modular files (placed under src)
|
|
3199
3200
|
await ctx.dump(providerMainTemplate(ctx.sources));
|
|
@@ -3244,12 +3245,12 @@ Use this TypeScript type anywhere you need static typing for this object shape i
|
|
|
3244
3245
|
|
|
3245
3246
|
## Import
|
|
3246
3247
|
${'```ts'}
|
|
3247
|
-
${importContent}
|
|
3248
|
+
${importContent.content}
|
|
3248
3249
|
${'```'}
|
|
3249
3250
|
|
|
3250
3251
|
## Definition
|
|
3251
3252
|
${'```ts'}
|
|
3252
|
-
${codeContent}
|
|
3253
|
+
${codeContent.content}
|
|
3253
3254
|
${'```'}
|
|
3254
3255
|
`;
|
|
3255
3256
|
}
|
|
@@ -3271,12 +3272,12 @@ Use this JSON Schema with tools that consume JSON Schema: UI form builders (e.g.
|
|
|
3271
3272
|
|
|
3272
3273
|
## Import
|
|
3273
3274
|
${'```ts'}
|
|
3274
|
-
${importContent}
|
|
3275
|
+
${importContent.content}
|
|
3275
3276
|
${'```'}
|
|
3276
3277
|
|
|
3277
3278
|
## Definition
|
|
3278
3279
|
${'```ts'}
|
|
3279
|
-
${codeContent}
|
|
3280
|
+
${codeContent.content}
|
|
3280
3281
|
${'```'}
|
|
3281
3282
|
`;
|
|
3282
3283
|
}
|
|
@@ -3298,12 +3299,12 @@ Use this Zod schema for runtime validation and parsing: form validation, client/
|
|
|
3298
3299
|
|
|
3299
3300
|
## Import
|
|
3300
3301
|
${'```ts'}
|
|
3301
|
-
${importContent}
|
|
3302
|
+
${importContent.content}
|
|
3302
3303
|
${'```'}
|
|
3303
3304
|
|
|
3304
3305
|
## Definition
|
|
3305
3306
|
${'```ts'}
|
|
3306
|
-
${codeContent}
|
|
3307
|
+
${codeContent.content}
|
|
3307
3308
|
${'```'}
|
|
3308
3309
|
`;
|
|
3309
3310
|
}
|
|
@@ -4310,6 +4311,19 @@ async function getEndpointDocumentation(result) {
|
|
|
4310
4311
|
return tabs;
|
|
4311
4312
|
}
|
|
4312
4313
|
|
|
4314
|
+
async function initPlugin(ctx) {
|
|
4315
|
+
// React plugin doesn't need any specific initialization tasks currently
|
|
4316
|
+
// But we return a postInit function to show instructions to the user
|
|
4317
|
+
return {
|
|
4318
|
+
postInit: ()=>{
|
|
4319
|
+
console.log(chalk.blue('\nš Next Steps:'));
|
|
4320
|
+
console.log(chalk.white('To complete your React setup, please refer to the post-initialization instructions at:'));
|
|
4321
|
+
console.log(chalk.cyan('https://intrig.dev/docs/react/initialization#3-post-initialization-steps'));
|
|
4322
|
+
console.log(chalk.gray('\nThis guide will show you how to add IntrigProvider to your React application.\n'));
|
|
4323
|
+
}
|
|
4324
|
+
};
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4313
4327
|
function createPlugin() {
|
|
4314
4328
|
return {
|
|
4315
4329
|
meta () {
|
|
@@ -4322,7 +4336,8 @@ function createPlugin() {
|
|
|
4322
4336
|
},
|
|
4323
4337
|
generate: generateCode,
|
|
4324
4338
|
getSchemaDocumentation,
|
|
4325
|
-
getEndpointDocumentation
|
|
4339
|
+
getEndpointDocumentation,
|
|
4340
|
+
init: initPlugin
|
|
4326
4341
|
};
|
|
4327
4342
|
}
|
|
4328
4343
|
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as path from 'path';
|
|
|
3
3
|
import path__default from 'path';
|
|
4
4
|
import * as fsx from 'fs-extra';
|
|
5
5
|
import * as mimeType from 'mime-types';
|
|
6
|
+
import chalk from 'chalk';
|
|
6
7
|
|
|
7
8
|
class InternalGeneratorContext {
|
|
8
9
|
getCounter(sourceId) {
|
|
@@ -1393,24 +1394,6 @@ function reactSwcrcTemplate() {
|
|
|
1393
1394
|
`;
|
|
1394
1395
|
}
|
|
1395
1396
|
|
|
1396
|
-
function intrigMiddlewareTemplate() {
|
|
1397
|
-
const ts = typescript(path.resolve('src', 'intrig-middleware.ts'));
|
|
1398
|
-
return ts`
|
|
1399
|
-
import axios from 'axios';
|
|
1400
|
-
import { requestInterceptor } from 'intrig-hook';
|
|
1401
|
-
|
|
1402
|
-
export function getAxiosInstance(key: string) {
|
|
1403
|
-
let axiosInstance = axios.create({
|
|
1404
|
-
baseURL: process.env[${"`${key.toUpperCase()}_API_URL`"}],
|
|
1405
|
-
});
|
|
1406
|
-
|
|
1407
|
-
axiosInstance.interceptors.request.use(requestInterceptor);
|
|
1408
|
-
|
|
1409
|
-
return axiosInstance;
|
|
1410
|
-
}
|
|
1411
|
-
`;
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
1397
|
function flushSyncUtilTemplate(ctx) {
|
|
1415
1398
|
var _packageJson_dependencies, _packageJson_devDependencies, _packageJson_peerDependencies;
|
|
1416
1399
|
const ts = typescript(path.resolve('src', 'utils', 'flush-sync.ts'));
|
|
@@ -1531,6 +1514,7 @@ function providerHooksTemplate() {
|
|
|
1531
1514
|
useMemo,
|
|
1532
1515
|
useState,
|
|
1533
1516
|
useRef,
|
|
1517
|
+
useEffect,
|
|
1534
1518
|
} from 'react';
|
|
1535
1519
|
import {
|
|
1536
1520
|
ErrorState,
|
|
@@ -1574,6 +1558,16 @@ export function useNetworkState<T>({
|
|
|
1574
1558
|
const context = useContext(Context);
|
|
1575
1559
|
|
|
1576
1560
|
const [abortController, setAbortController] = useState<AbortController>();
|
|
1561
|
+
|
|
1562
|
+
const contextRef = useRef(context);
|
|
1563
|
+
const schemaRef = useRef(schema);
|
|
1564
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
1565
|
+
|
|
1566
|
+
useEffect(() => {
|
|
1567
|
+
contextRef.current = context;
|
|
1568
|
+
schemaRef.current = schema;
|
|
1569
|
+
errorSchemaRef.current = errorSchema;
|
|
1570
|
+
});
|
|
1577
1571
|
|
|
1578
1572
|
const networkState = useMemo(() => {
|
|
1579
1573
|
logger.info(${"`Updating status ${key} ${operation} ${source}`"});
|
|
@@ -1582,7 +1576,7 @@ export function useNetworkState<T>({
|
|
|
1582
1576
|
(context.state?.[${"`${source}:${operation}:${key}`"}] as NetworkState<T>) ??
|
|
1583
1577
|
init()
|
|
1584
1578
|
);
|
|
1585
|
-
}, [
|
|
1579
|
+
}, [context.state, key, operation, source]);
|
|
1586
1580
|
|
|
1587
1581
|
const dispatch = useCallback(
|
|
1588
1582
|
(state: NetworkState<T>) => {
|
|
@@ -1630,30 +1624,30 @@ export function useNetworkState<T>({
|
|
|
1630
1624
|
signal: abortController.signal,
|
|
1631
1625
|
};
|
|
1632
1626
|
|
|
1633
|
-
await
|
|
1627
|
+
await contextRef.current.execute(
|
|
1634
1628
|
requestConfig,
|
|
1635
1629
|
dispatch,
|
|
1636
|
-
|
|
1637
|
-
|
|
1630
|
+
schemaRef.current,
|
|
1631
|
+
errorSchemaRef.current as any,
|
|
1638
1632
|
);
|
|
1639
1633
|
},
|
|
1640
|
-
[
|
|
1634
|
+
[dispatch, key, operation, source],
|
|
1641
1635
|
);
|
|
1642
1636
|
|
|
1643
1637
|
const deboundedExecute = useMemo(
|
|
1644
|
-
() => debounce(execute, debounceDelay
|
|
1645
|
-
[execute],
|
|
1638
|
+
() => debounce(execute, debounceDelay),
|
|
1639
|
+
[execute, debounceDelay],
|
|
1646
1640
|
);
|
|
1647
1641
|
|
|
1648
1642
|
const clear = useCallback(() => {
|
|
1649
1643
|
logger.info(${"`Clearing request ${key} ${operation} ${source}`"});
|
|
1650
1644
|
dispatch(init());
|
|
1651
|
-
setAbortController((
|
|
1645
|
+
setAbortController((prev) => {
|
|
1652
1646
|
logger.info(${"`Aborting request ${key} ${operation} ${source}`"});
|
|
1653
|
-
|
|
1647
|
+
prev?.abort();
|
|
1654
1648
|
return undefined;
|
|
1655
1649
|
});
|
|
1656
|
-
}, [dispatch,
|
|
1650
|
+
}, [dispatch, key, operation, source]);
|
|
1657
1651
|
|
|
1658
1652
|
return [networkState, deboundedExecute, clear, dispatch];
|
|
1659
1653
|
}
|
|
@@ -1670,6 +1664,14 @@ export function useTransitionCall<T>({
|
|
|
1670
1664
|
}): [(request: RequestType) => Promise<T>, () => void] {
|
|
1671
1665
|
const ctx = useContext(Context);
|
|
1672
1666
|
const controller = useRef<AbortController | undefined>(undefined);
|
|
1667
|
+
|
|
1668
|
+
const schemaRef = useRef(schema);
|
|
1669
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
1670
|
+
|
|
1671
|
+
useEffect(() => {
|
|
1672
|
+
schemaRef.current = schema;
|
|
1673
|
+
errorSchemaRef.current = errorSchema;
|
|
1674
|
+
});
|
|
1673
1675
|
|
|
1674
1676
|
const call = useCallback(
|
|
1675
1677
|
async (request: RequestType) => {
|
|
@@ -1687,12 +1689,12 @@ export function useTransitionCall<T>({
|
|
|
1687
1689
|
reject(state.error);
|
|
1688
1690
|
}
|
|
1689
1691
|
},
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
+
schemaRef.current,
|
|
1693
|
+
errorSchemaRef.current,
|
|
1692
1694
|
);
|
|
1693
1695
|
});
|
|
1694
1696
|
},
|
|
1695
|
-
[ctx
|
|
1697
|
+
[ctx],
|
|
1696
1698
|
);
|
|
1697
1699
|
|
|
1698
1700
|
const abort = useCallback(() => {
|
|
@@ -3169,7 +3171,6 @@ async function generateCode(ctx) {
|
|
|
3169
3171
|
await ctx.dump(reactExtraTemplate());
|
|
3170
3172
|
await ctx.dump(reactMediaTypeUtilsTemplate());
|
|
3171
3173
|
await ctx.dump(typeUtilsTemplate());
|
|
3172
|
-
await ctx.dump(intrigMiddlewareTemplate());
|
|
3173
3174
|
await ctx.dump(flushSyncUtilTemplate(ctx));
|
|
3174
3175
|
// Provider modular files (placed under src)
|
|
3175
3176
|
await ctx.dump(providerMainTemplate(ctx.sources));
|
|
@@ -3220,12 +3221,12 @@ Use this TypeScript type anywhere you need static typing for this object shape i
|
|
|
3220
3221
|
|
|
3221
3222
|
## Import
|
|
3222
3223
|
${'```ts'}
|
|
3223
|
-
${importContent}
|
|
3224
|
+
${importContent.content}
|
|
3224
3225
|
${'```'}
|
|
3225
3226
|
|
|
3226
3227
|
## Definition
|
|
3227
3228
|
${'```ts'}
|
|
3228
|
-
${codeContent}
|
|
3229
|
+
${codeContent.content}
|
|
3229
3230
|
${'```'}
|
|
3230
3231
|
`;
|
|
3231
3232
|
}
|
|
@@ -3247,12 +3248,12 @@ Use this JSON Schema with tools that consume JSON Schema: UI form builders (e.g.
|
|
|
3247
3248
|
|
|
3248
3249
|
## Import
|
|
3249
3250
|
${'```ts'}
|
|
3250
|
-
${importContent}
|
|
3251
|
+
${importContent.content}
|
|
3251
3252
|
${'```'}
|
|
3252
3253
|
|
|
3253
3254
|
## Definition
|
|
3254
3255
|
${'```ts'}
|
|
3255
|
-
${codeContent}
|
|
3256
|
+
${codeContent.content}
|
|
3256
3257
|
${'```'}
|
|
3257
3258
|
`;
|
|
3258
3259
|
}
|
|
@@ -3274,12 +3275,12 @@ Use this Zod schema for runtime validation and parsing: form validation, client/
|
|
|
3274
3275
|
|
|
3275
3276
|
## Import
|
|
3276
3277
|
${'```ts'}
|
|
3277
|
-
${importContent}
|
|
3278
|
+
${importContent.content}
|
|
3278
3279
|
${'```'}
|
|
3279
3280
|
|
|
3280
3281
|
## Definition
|
|
3281
3282
|
${'```ts'}
|
|
3282
|
-
${codeContent}
|
|
3283
|
+
${codeContent.content}
|
|
3283
3284
|
${'```'}
|
|
3284
3285
|
`;
|
|
3285
3286
|
}
|
|
@@ -4286,6 +4287,19 @@ async function getEndpointDocumentation(result) {
|
|
|
4286
4287
|
return tabs;
|
|
4287
4288
|
}
|
|
4288
4289
|
|
|
4290
|
+
async function initPlugin(ctx) {
|
|
4291
|
+
// React plugin doesn't need any specific initialization tasks currently
|
|
4292
|
+
// But we return a postInit function to show instructions to the user
|
|
4293
|
+
return {
|
|
4294
|
+
postInit: ()=>{
|
|
4295
|
+
console.log(chalk.blue('\nš Next Steps:'));
|
|
4296
|
+
console.log(chalk.white('To complete your React setup, please refer to the post-initialization instructions at:'));
|
|
4297
|
+
console.log(chalk.cyan('https://intrig.dev/docs/react/initialization#3-post-initialization-steps'));
|
|
4298
|
+
console.log(chalk.gray('\nThis guide will show you how to add IntrigProvider to your React application.\n'));
|
|
4299
|
+
}
|
|
4300
|
+
};
|
|
4301
|
+
}
|
|
4302
|
+
|
|
4289
4303
|
function createPlugin() {
|
|
4290
4304
|
return {
|
|
4291
4305
|
meta () {
|
|
@@ -4298,7 +4312,8 @@ function createPlugin() {
|
|
|
4298
4312
|
},
|
|
4299
4313
|
generate: generateCode,
|
|
4300
4314
|
getSchemaDocumentation,
|
|
4301
|
-
getEndpointDocumentation
|
|
4315
|
+
getEndpointDocumentation,
|
|
4316
|
+
init: initPlugin
|
|
4302
4317
|
};
|
|
4303
4318
|
}
|
|
4304
4319
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intrig/plugin-react",
|
|
3
|
-
"version": "0.0.2-
|
|
3
|
+
"version": "0.0.2-7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@intrig/plugin-sdk": "^0.0.2-
|
|
18
|
+
"@intrig/plugin-sdk": "^0.0.2-7",
|
|
19
19
|
"@swc/helpers": "~0.5.11"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|