@opengis/fastify-table 1.2.19 → 1.2.21

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/index.js CHANGED
@@ -1,79 +1,82 @@
1
- import path from 'node:path';
2
- import fp from 'fastify-plugin';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import config from './config.js';
6
-
7
- // plugins
8
- import cronPlugin from './server/plugins/cron/index.js';
9
- import crudPlugin from './server/plugins/crud/index.js';
10
- // hook, logger, migration - utils only
11
- import pgPlugin from './server/plugins/pg/index.js';
12
- import policyPlugin from './server/plugins/policy/index.js';
13
- import redisPlugin from './server/plugins/redis/index.js';
14
- import tablePlugin from './server/plugins/table/index.js';
15
- import utilPlugin from './server/plugins/util/index.js';
16
- import loggerPlugin from './server/plugins/logger/index.js';
17
-
18
- // routes
19
- import cronRoutes from './server/routes/cron/index.js';
20
- import crudRoutes from './server/routes/crud/index.js';
21
- import loggerRoutes from './server/routes/logger/index.js';
22
- import propertiesRoutes from './server/routes/properties/index.js';
23
- import tableRoutes from './server/routes/table/index.js';
24
- import utilRoutes from './server/routes/util/index.js';
25
-
26
- import {
27
- addTemplateDir, execMigrations,
28
- } from './utils.js';
29
-
30
- async function plugin(fastify, opt) {
31
- config.pg = opt.pg;
32
- config.redis = opt.redis;
33
- config.root = opt.root;
34
- config.mapServerRoot = opt.mapServerRoot;
35
-
36
- // independent npm start / unit test
37
- if (!fastify.config) {
38
- fastify.decorate('config', config);
39
- }
40
-
41
- fastify.register(import('@fastify/sensible'), {
42
- errorHandler: false,
43
- });
44
-
45
- fastify.register(import('@fastify/url-data'), {
46
- errorHandler: false,
47
- });
48
-
49
- fastify.register(import('@opengis/fastify-hb'));
50
-
51
- const filename = fileURLToPath(import.meta.url);
52
- const cwd = path.dirname(filename);
53
-
54
- // core migrations (second argument for core only)
55
- execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
56
-
57
- // core templates && cls
58
- config.templates?.forEach(el => addTemplateDir(el));
59
- addTemplateDir(path.join(cwd, 'module/core'));
60
-
61
- // plugins / utils / funcs
62
- policyPlugin(fastify);
63
- redisPlugin(fastify);
64
- await pgPlugin(fastify, opt);
65
- tablePlugin(fastify, opt);
66
- crudPlugin(fastify, opt);
67
- utilPlugin(fastify, opt);
68
- cronPlugin(fastify, opt);
69
- loggerPlugin(fastify, opt);
70
-
71
- // routes / api
72
- cronRoutes(fastify, opt);
73
- crudRoutes(fastify, opt);
74
- loggerRoutes(fastify, opt);
75
- propertiesRoutes(fastify, opt);
76
- tableRoutes(fastify, opt);
77
- utilRoutes(fastify, opt);
78
- }
79
- export default fp(plugin);
1
+ import path from 'node:path';
2
+ import fp from 'fastify-plugin';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import config from './config.js';
6
+
7
+ // plugins
8
+ import cronPlugin from './server/plugins/cron/index.js';
9
+ import crudPlugin from './server/plugins/crud/index.js';
10
+ // hook, logger, migration - utils only
11
+ import pgPlugin from './server/plugins/pg/index.js';
12
+ import policyPlugin from './server/plugins/policy/index.js';
13
+ import metricPlugin from './server/plugins/metric/index.js';
14
+ import redisPlugin from './server/plugins/redis/index.js';
15
+ import tablePlugin from './server/plugins/table/index.js';
16
+ import utilPlugin from './server/plugins/util/index.js';
17
+ import loggerPlugin from './server/plugins/logger/index.js';
18
+
19
+ // routes
20
+ import cronRoutes from './server/routes/cron/index.js';
21
+ import crudRoutes from './server/routes/crud/index.js';
22
+ import loggerRoutes from './server/routes/logger/index.js';
23
+ import propertiesRoutes from './server/routes/properties/index.js';
24
+ import tableRoutes from './server/routes/table/index.js';
25
+ import utilRoutes from './server/routes/util/index.js';
26
+
27
+ import {
28
+ addTemplateDir, execMigrations,
29
+ } from './utils.js';
30
+
31
+ // core templates && cls
32
+ const filename = fileURLToPath(import.meta.url);
33
+ const cwd = path.dirname(filename);
34
+
35
+ async function plugin(fastify, opt) {
36
+ config.pg = opt.pg;
37
+ config.redis = opt.redis;
38
+ config.root = opt.root;
39
+ config.mapServerRoot = opt.mapServerRoot;
40
+
41
+ // independent npm start / unit test
42
+ if (!fastify.config) {
43
+ fastify.decorate('config', config);
44
+ }
45
+
46
+ fastify.register(import('@fastify/sensible'), {
47
+ errorHandler: false,
48
+ });
49
+
50
+ fastify.register(import('@fastify/url-data'), {
51
+ errorHandler: false,
52
+ });
53
+
54
+ fastify.register(import('@opengis/fastify-hb'));
55
+
56
+ // core migrations (second argument for core only)
57
+ execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
58
+
59
+ // core templates && cls
60
+ config.templates?.forEach(el => addTemplateDir(el));
61
+ addTemplateDir(path.join(cwd, 'module/core'));
62
+
63
+ // plugins / utils / funcs
64
+ policyPlugin(fastify);
65
+ metricPlugin(fastify);
66
+ redisPlugin(fastify);
67
+ await pgPlugin(fastify, opt);
68
+ tablePlugin(fastify, opt);
69
+ crudPlugin(fastify, opt);
70
+ utilPlugin(fastify, opt);
71
+ cronPlugin(fastify, opt);
72
+ loggerPlugin(fastify, opt);
73
+
74
+ // routes / api
75
+ cronRoutes(fastify, opt);
76
+ crudRoutes(fastify, opt);
77
+ loggerRoutes(fastify, opt);
78
+ propertiesRoutes(fastify, opt);
79
+ tableRoutes(fastify, opt);
80
+ utilRoutes(fastify, opt);
81
+ }
82
+ export default fp(plugin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.2.19",
3
+ "version": "1.2.21",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,84 +1,84 @@
1
- -- fix error if function exists and return type not text i.e bigint
2
-
3
- do $$
4
-
5
- declare
6
- m record;
7
- _pk text;
8
- _tables json;
9
- _returnType text;
10
-
11
- begin
12
-
13
- select format_type(p.prorettype, null) as return_type
14
- from pg_proc p
15
- where p.proname = 'next_id'
16
- and p.pronamespace = 'public'::regnamespace into _returnType;
17
-
18
- if (_returnType != 'text') then
19
- raise notice 'default reassign start: % -> text', _returnType;
20
-
21
- CREATE EXTENSION if not exists "uuid-ossp";
22
-
23
- SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
- FROM pg_catalog.pg_attribute a
25
- LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
- WHERE NOT a.attisdropped -- no dropped (dead) columns
27
- AND a.attnum > 0 -- no system columns
28
- AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
-
30
- FOR m in (select json_object_keys(_tables) as table) loop
31
- _pk = _tables->>m.table;
32
- raise notice 'drop default: %,%', m.table, _pk;
33
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
- end loop;
35
-
36
- DROP FUNCTION IF EXISTS next_id();
37
-
38
- /* CREATE EXTENSION if not exists "uuid-ossp";
39
- ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
40
-
41
- CREATE OR REPLACE FUNCTION next_id()
42
- RETURNS text AS
43
- $BODY$
44
- DECLARE
45
-
46
- BEGIN
47
- -- return replace(public.uuid_generate_v4()::text, '-', '');
48
- -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
49
- return encode(public.gen_random_bytes(6), 'hex');
50
- END;
51
- $BODY$
52
- LANGUAGE plpgsql VOLATILE
53
- COST 100;
54
-
55
- FOR m in (select json_object_keys(_tables) as table) loop
56
- _pk = _tables->>m.table;
57
- raise notice 'reassign default: %, %', m.table, _pk;
58
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
59
- end loop;
60
-
61
- raise notice 'reassign default finish: %', _tables;
62
-
63
- else
64
- raise notice 'skip default reassign';
65
-
66
- /* CREATE EXTENSION if not exists "uuid-ossp";
67
- ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
68
-
69
- CREATE OR REPLACE FUNCTION next_id()
70
- RETURNS text AS
71
- $BODY$
72
- DECLARE
73
-
74
- BEGIN
75
- -- return replace(public.uuid_generate_v4()::text, '-', '');
76
- -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
77
- return encode(public.gen_random_bytes(6), 'hex');
78
- END;
79
- $BODY$
80
- LANGUAGE plpgsql VOLATILE
81
- COST 100;
82
- end if;
83
-
84
- end $$
1
+ -- fix error if function exists and return type not text i.e bigint
2
+
3
+ do $$
4
+
5
+ declare
6
+ m record;
7
+ _pk text;
8
+ _tables json;
9
+ _returnType text;
10
+
11
+ begin
12
+
13
+ select format_type(p.prorettype, null) as return_type
14
+ from pg_proc p
15
+ where p.proname = 'next_id'
16
+ and p.pronamespace = 'public'::regnamespace into _returnType;
17
+
18
+ if (_returnType != 'text') then
19
+ raise notice 'default reassign start: % -> text', _returnType;
20
+
21
+ CREATE EXTENSION if not exists "uuid-ossp";
22
+
23
+ SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
+ FROM pg_catalog.pg_attribute a
25
+ LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
+ WHERE NOT a.attisdropped -- no dropped (dead) columns
27
+ AND a.attnum > 0 -- no system columns
28
+ AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
+
30
+ FOR m in (select json_object_keys(_tables) as table) loop
31
+ _pk = _tables->>m.table;
32
+ raise notice 'drop default: %,%', m.table, _pk;
33
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
+ end loop;
35
+
36
+ DROP FUNCTION IF EXISTS next_id();
37
+
38
+ /* CREATE EXTENSION if not exists "uuid-ossp";
39
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
40
+
41
+ CREATE OR REPLACE FUNCTION next_id()
42
+ RETURNS text AS
43
+ $BODY$
44
+ DECLARE
45
+
46
+ BEGIN
47
+ -- return replace(public.uuid_generate_v4()::text, '-', '');
48
+ -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
49
+ return encode(public.gen_random_bytes(6), 'hex');
50
+ END;
51
+ $BODY$
52
+ LANGUAGE plpgsql VOLATILE
53
+ COST 100;
54
+
55
+ FOR m in (select json_object_keys(_tables) as table) loop
56
+ _pk = _tables->>m.table;
57
+ raise notice 'reassign default: %, %', m.table, _pk;
58
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
59
+ end loop;
60
+
61
+ raise notice 'reassign default finish: %', _tables;
62
+
63
+ else
64
+ raise notice 'skip default reassign';
65
+
66
+ /* CREATE EXTENSION if not exists "uuid-ossp";
67
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
68
+
69
+ CREATE OR REPLACE FUNCTION next_id()
70
+ RETURNS text AS
71
+ $BODY$
72
+ DECLARE
73
+
74
+ BEGIN
75
+ -- return replace(public.uuid_generate_v4()::text, '-', '');
76
+ -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
77
+ return encode(public.gen_random_bytes(6), 'hex');
78
+ END;
79
+ $BODY$
80
+ LANGUAGE plpgsql VOLATILE
81
+ COST 100;
82
+ end if;
83
+
84
+ end $$